diff options
Diffstat (limited to 'uploader/__init__.py')
-rw-r--r-- | uploader/__init__.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/uploader/__init__.py b/uploader/__init__.py index cae531b..23e66c1 100644 --- a/uploader/__init__.py +++ b/uploader/__init__.py @@ -6,6 +6,9 @@ from pathlib import Path from flask import Flask, request from flask_session import Session +from cachelib import FileSystemCache + +from gn_libs import jobs as gnlibs_jobs from uploader.oauth2.client import user_logged_in, authserver_authorise_uri @@ -51,9 +54,15 @@ def setup_logging(app: Flask) -> Flask: return __log_gunicorn__(app) if bool(software) else __log_dev__(app) -def create_app(): - """The application factory""" +def create_app(config: dict = {}): + """The application factory. + + config: dict + Useful to override settings in the settings files and environment + especially in environments such as testing.""" app = Flask(__name__) + + ### BEGIN: Application configuration app.config.from_pyfile( Path(__file__).parent.joinpath("default_settings.py")) if "UPLOADER_CONF" in os.environ: @@ -68,6 +77,13 @@ def create_app(): if secretsfile.exists(): # Silently ignore secrets if the file does not exist. app.config.from_pyfile(secretsfile) + app.config.update(config) # Override everything with passed in config + ### END: Application configuration + + app.config["SESSION_CACHELIB"] = FileSystemCache( + cache_dir=Path(app.config["SESSION_FILESYSTEM_CACHE_PATH"]).absolute(), + threshold=int(app.config["SESSION_FILESYSTEM_CACHE_THRESHOLD"]), + default_timeout=int(app.config["SESSION_FILESYSTEM_CACHE_TIMEOUT"])) setup_logging(app) @@ -88,4 +104,5 @@ def create_app(): app.register_blueprint(speciesbp, url_prefix="/species") register_error_handlers(app) + gnlibs_jobs.init_app(app) return app |