From c1a5c92b64fed4aa56952d031f567a00fa44787d Mon Sep 17 00:00:00 2001
From: NolanB <nboukachab@teklia.com>
Date: Mon, 11 Jul 2022 10:07:17 +0200
Subject: [PATCH] Move the cache config to method configure_cache

---
 arkindex_worker/worker/__init__.py | 2 ++
 arkindex_worker/worker/base.py     | 1 +
 tests/conftest.py                  | 1 +
 tests/test_merge.py                | 1 +
 4 files changed, 5 insertions(+)

diff --git a/arkindex_worker/worker/__init__.py b/arkindex_worker/worker/__init__.py
index 25696d60..37998b10 100644
--- a/arkindex_worker/worker/__init__.py
+++ b/arkindex_worker/worker/__init__.py
@@ -137,6 +137,8 @@ class ElementsWorker(
 
     def configure(self):
         super().configure()
+        super().configure_cache()
+
         # Add report concerning elements
         self.report = Reporter(
             **self.worker_details, version=getattr(self, "worker_version_id", None)
diff --git a/arkindex_worker/worker/base.py b/arkindex_worker/worker/base.py
index 56079e7a..94a0da01 100644
--- a/arkindex_worker/worker/base.py
+++ b/arkindex_worker/worker/base.py
@@ -211,6 +211,7 @@ class BaseWorker(object):
             logger.setLevel(logging.DEBUG)
             logger.debug("Debug output enabled")
 
+    def configure_cache(self):
         task_id = os.environ.get("PONOS_TASK")
         paths = None
         if self.support_cache and self.args.database is not None:
diff --git a/tests/conftest.py b/tests/conftest.py
index b82138f8..64af8eb1 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -286,6 +286,7 @@ def mock_elements_worker_with_cache(monkeypatch, mock_config_api, tmp_path):
 
     worker = ElementsWorker(support_cache=True)
     worker.configure()
+    worker.configure_cache()
     return worker
 
 
diff --git a/tests/test_merge.py b/tests/test_merge.py
index 687b7792..764287a9 100644
--- a/tests/test_merge.py
+++ b/tests/test_merge.py
@@ -182,6 +182,7 @@ def test_merge_from_worker(
     # Create the task's output dir, so that it can create its own database
     (tmpdir / "my_task").mkdir()
     mock_base_worker_with_cache.configure()
+    mock_base_worker_with_cache.configure_cache()
 
     # Then we have 2 elements and a transcription
     assert CachedImage.select().count() == 0
-- 
GitLab