diff --git a/arkindex_worker/worker.py b/arkindex_worker/worker.py index 839ee99f9d0514f7732ac5eacd197cd0bdac27c4..ec61b14b3677dcdc7bf7a89ebb1c15966b2213a0 100644 --- a/arkindex_worker/worker.py +++ b/arkindex_worker/worker.py @@ -50,9 +50,7 @@ class BaseWorker(object): logger.info(f"Worker will use {self.work_dir} as working directory") - self.use_cache = use_cache - - if self.use_cache: + if use_cache is True: if os.environ.get("TASK_ID") and os.path.isdir(CACHE_DIR): cache_path = os.path.join(CACHE_DIR, "db.sqlite") else: @@ -60,6 +58,9 @@ class BaseWorker(object): self.cache = LocalDB(cache_path) self.cache.create_tables() + else: + self.cache = None + logger.debug("Cache is disabled") @property def is_read_only(self): @@ -466,7 +467,7 @@ class ElementsWorker(BaseWorker): for element in elements: self.report.add_element(parent.id, element["type"]) - if self.use_cache: + if self.cache: # Store elements in local cache try: parent_id_hex = convert_str_uuid_to_hex(parent.id) diff --git a/tests/test_base_worker.py b/tests/test_base_worker.py index 72a0590cbc54b2b71f17652655c7a09fedc82660..47a7bef953ef8602b632a541f3aaf34ce43f2ed3 100644 --- a/tests/test_base_worker.py +++ b/tests/test_base_worker.py @@ -33,8 +33,7 @@ def test_init_with_local_cache(monkeypatch): assert worker.work_dir == os.path.expanduser("~/.local/share/arkindex") assert worker.worker_version_id == "12341234-1234-1234-1234-123412341234" - assert worker.use_cache - assert worker.cache + assert worker.cache is not None def test_init_var_ponos_data_given(monkeypatch):