Repository: reanahub/reana-job-controller

Issue:
cache: investigate and possibly disable caching
Caching has caused an issue recently (see https://github.com/reanahub/reana-job-controller/issues/420) even though it is not enabled in REANA. In particular, the config variable `CACHE_ENABLED` is used in reana-workflow-engine-serial to disable the caching mechanism, but it seems like this is not enough as there is more caching logic in reana-job-controller that is always executed for every workflow.

We should investigate what this logic is doing and whether it's safe to disable it using the same `CACHE_ENABLED` flag. Note that this should improve performance, as currently we are saving lots of file metadata to the database, even though they are then not used:
https://github.com/reanahub/reana-job-controller/blob/e6742f2911df46dfbef3b7e9104330d58e2b4211/reana_job_controller/job_manager.py#L127-L137

Discussion:

Patch:
diff --git a/reana_job_controller/config.py b/reana_job_controller/config.py
index 93d3a69..e1bc02b 100644
--- a/reana_job_controller/config.py
+++ b/reana_job_controller/config.py
@@ -14,6 +14,9 @@ from reana_commons.config import REANA_COMPONENT_PREFIX
 
 from werkzeug.utils import import_string
 
+CACHE_ENABLED = False
+"""Determines if jobs caching is enabled."""
+
 SHARED_VOLUME_PATH_ROOT = os.getenv("SHARED_VOLUME_PATH_ROOT", "/var/reana")
 """Root path of the shared volume ."""
 
diff --git a/reana_job_controller/job_manager.py b/reana_job_controller/job_manager.py
index b4236ae..7bb1583 100644
--- a/reana_job_controller/job_manager.py
+++ b/reana_job_controller/job_manager.py
@@ -15,6 +15,8 @@ from reana_db.database import Session, engine as db_engine
 from reana_db.models import Job as JobTable
 from reana_db.models import JobCache, JobStatus, Workflow
 
+from reana_job_controller.config import CACHE_ENABLED
+
 
 class JobManager:
     """Job management interface."""
@@ -61,7 +63,8 @@ class JobManager:
             inst.before_execution()
             backend_job_id = fn(inst, *args, **kwargs)
             inst.create_job_in_db(backend_job_id)
-            inst.cache_job()
+            if CACHE_ENABLED:
+                inst.cache_job()
             db_engine.dispose()
             return backend_job_id
 


Test patch:
diff --git a/tests/test_job_manager.py b/tests/test_job_manager.py
index 10a5c14..e3611b9 100644
--- a/tests/test_job_manager.py
+++ b/tests/test_job_manager.py
@@ -131,6 +131,7 @@ def test_stop_kubernetes_job(
             kubernetes_client.delete_namespaced_job.assert_called_once()
 
 
+@mock.patch("reana_job_controller.job_manager.CACHE_ENABLED", True)
 def test_execution_hooks():
     """Test hook execution order."""