about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2026-01-26 13:52:57 -0600
committerFrederick Muriuki Muriithi2026-01-26 14:11:38 -0600
commit49c3f72fa0f9f68e463d8a883b3d1786ec4c0768 (patch)
treecd407ac9bb8411eb3df9d8a2d522c56ae21bff44
parent79386454b1d87d5b4c1ace22e7b272a71fd205be (diff)
downloadgn-uploader-49c3f72fa0f9f68e463d8a883b3d1786ec4c0768.tar.gz
Replace TEMPORARY_DIRECTORY with SCRATCH_DIRECTORY
Avoid using the terminology "TEMPORARY_DIRECTORY" which encourages use
of the shared global mutable state in /tmp, that we want to move away
from. Instead, we use "SCRATCH_DIRECTORY" which is an explicit
specified directory for state needed for and by the gn-uploader
application.
-rw-r--r--uploader/__init__.py9
-rw-r--r--uploader/default_settings.py7
-rw-r--r--uploader/phenotypes/views.py2
3 files changed, 16 insertions, 2 deletions
diff --git a/uploader/__init__.py b/uploader/__init__.py
index 0ba1f81..a28ed8d 100644
--- a/uploader/__init__.py
+++ b/uploader/__init__.py
@@ -73,6 +73,14 @@ def setup_modules_logging(app_logger, modules):
         _logger.setLevel(loglevel)
 
 
+def __setup_scratch_directory__(app: Flask) -> Flask:
+    app.config["SCRATCH_DIRECTORY"] = Path(
+        app.config["SCRATCH_DIRECTORY"]).absolute()
+    return app
+
+def update_unspecified_defaults(app: Flask):
+    """Setup the defaults for necessary configurations that do not have values specified for them."""
+    __setup_scratch_directory__(app)
 def create_app(config: Optional[dict] = None):
     """The application factory.
 
@@ -100,6 +108,7 @@ def create_app(config: Optional[dict] = None):
             # Silently ignore secrets if the file does not exist.
             app.config.from_pyfile(secretsfile)
     app.config.update(config) # Override everything with passed in config
+    update_unspecified_defaults(app)
     ### END: Application configuration
 
     app.config["SESSION_CACHELIB"] = FileSystemCache(
diff --git a/uploader/default_settings.py b/uploader/default_settings.py
index 52cdad5..75dc53a 100644
--- a/uploader/default_settings.py
+++ b/uploader/default_settings.py
@@ -6,7 +6,12 @@ actual configuration file used for the production and staging systems.
 LOG_LEVEL = "WARNING"
 SECRET_KEY = b"<Please! Please! Please! Change This!>"
 UPLOAD_FOLDER = "/tmp/qc_app_files"
-TEMPORARY_DIRECTORY = "/tmp/gn-uploader-tmpdir"
+
+# Scratch directory and uploads:
+# *** The scratch directory ***
+# We avoid `/tmp` entirely for the scratch directory to avoid shared global
+# mutable state with other users/applications/processes.
+SCRATCH_DIRECTORY = "~/tmp/gn-uploader-scratchdir"
 REDIS_URL = "redis://"
 JOBS_TTL_SECONDS = 1209600 # 14 days
 GNQC_REDIS_PREFIX="gn-uploader"
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index 5ade24d..b6a8c86 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -1105,7 +1105,7 @@ def rerun_qtlreaper(# pylint: disable=[unused-argument]
     _job_id = uuid.uuid4()
     _loglevel = logging.getLevelName(app.logger.getEffectiveLevel()).lower()
 
-    _workingdir = Path(app.config["TEMPORARY_DIRECTORY"]).joinpath("qtlreaper")
+    _workingdir = Path(app.config["SCRATCH_DIRECTORY"]).joinpath("qtlreaper")
     _workingdir.mkdir(exist_ok=True)
     command = [
         sys.executable,