From d8e5f6552e8921af05f77adcc40c48096c26e36f Mon Sep 17 00:00:00 2001 From: krateng Date: Fri, 31 Mar 2023 17:31:46 +0200 Subject: [PATCH] Improved aux mode again --- maloja/database/__init__.py | 12 ++---------- maloja/database/dbcache.py | 1 - maloja/pkg_global/conf.py | 2 ++ maloja/proccontrol/tasks/import_scrobbles.py | 3 --- maloja/proccontrol/tasks/parse_albums.py | 6 +----- maloja/server.py | 3 +++ 6 files changed, 8 insertions(+), 19 deletions(-) diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index f37910e..4549c9d 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -2,20 +2,12 @@ from bottle import request, response, FormsDict -# we're running an auxiliary task that doesn't require all the random background -# nonsense to be fired up -# this is temporary -# FIX YO DAMN ARCHITECTURE ALREADY -AUX_MODE = False -def set_aux_mode(): - global AUX_MODE - AUX_MODE = True - # decorator that makes sure this function is only run in normal operation, # not when we run a task that needs to access the database def no_aux_mode(func): def wrapper(*args,**kwargs): - if AUX_MODE: return + from ..pkg_global import conf + if conf.AUX_MODE: return return func(*args,**kwargs) return wrapper diff --git a/maloja/database/dbcache.py b/maloja/database/dbcache.py index da812a5..42695dc 100644 --- a/maloja/database/dbcache.py +++ b/maloja/database/dbcache.py @@ -98,7 +98,6 @@ if malojaconfig['USE_GLOBAL_CACHE']: def invalidate_entity_cache(): entitycache.clear() - @no_aux_mode def trim_cache(): ramprct = psutil.virtual_memory().percent if ramprct > malojaconfig["DB_MAX_MEMORY"]: diff --git a/maloja/pkg_global/conf.py b/maloja/pkg_global/conf.py index f519dc5..5d9b885 100644 --- a/maloja/pkg_global/conf.py +++ b/maloja/pkg_global/conf.py @@ -6,6 +6,8 @@ from doreah.configuration import types as tp from ..__pkginfo__ import VERSION +# this mode specifies whether we run some auxiliary task instead of the main server +AUX_MODE = True # if DATA_DIRECTORY is specified, this is the directory to use for EVERYTHING, no matter what diff --git a/maloja/proccontrol/tasks/import_scrobbles.py b/maloja/proccontrol/tasks/import_scrobbles.py index b34ccc0..1bab1c6 100644 --- a/maloja/proccontrol/tasks/import_scrobbles.py +++ b/maloja/proccontrol/tasks/import_scrobbles.py @@ -21,9 +21,6 @@ outputs = { def import_scrobbles(inputf): - from ...database import set_aux_mode - set_aux_mode() - from ...database.sqldb import add_scrobbles result = { diff --git a/maloja/proccontrol/tasks/parse_albums.py b/maloja/proccontrol/tasks/parse_albums.py index 125df0c..afeb8c9 100644 --- a/maloja/proccontrol/tasks/parse_albums.py +++ b/maloja/proccontrol/tasks/parse_albums.py @@ -1,11 +1,7 @@ - - +from doreah.io import col def parse_albums(replace=False): - from ...database import set_aux_mode - set_aux_mode() - from ...database.sqldb import guess_albums, get_album_id, add_track_to_album print("Parsing album information...") diff --git a/maloja/server.py b/maloja/server.py index 6f76524..a071c98 100644 --- a/maloja/server.py +++ b/maloja/server.py @@ -22,6 +22,7 @@ from .database.jinjaview import JinjaDBConnection from .images import resolve_track_image, resolve_artist_image, resolve_album_image from .malojauri import uri_to_internal, remove_identical from .pkg_global.conf import malojaconfig, data_dir +from .pkg_global import conf from .jinjaenv.context import jinja_environment from .apis import init_apis, apikeystore @@ -285,6 +286,8 @@ logging.getLogger().addHandler(WaitressLogHandler()) def run_server(): + conf.AUX_MODE = False + log("Starting up Maloja server...") ## start database