Skip to content

Commit

Permalink
perf(cache): avoid caching jobs when the cache is disabled (#435)
Browse files Browse the repository at this point in the history
Closes #422
  • Loading branch information
mdonadoni committed Feb 20, 2024
1 parent 42622fa commit 553468f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions reana_job_controller/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

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 ."""

Expand Down
5 changes: 4 additions & 1 deletion reana_job_controller/job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
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."""
Expand Down Expand Up @@ -61,7 +63,8 @@ def wrapper(inst, *args, **kwargs):
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

Expand Down
1 change: 1 addition & 0 deletions tests/test_job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down

0 comments on commit 553468f

Please sign in to comment.