Skip to content
Snippets Groups Projects

Refactoring use_cache attribute on Worker classes

Merged Eva Bardou requested to merge detect-use-cache into master
All threads resolved!
3 files
+ 53
28
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -18,7 +18,12 @@ from tenacity import (
from arkindex import ArkindexClient, options_from_env
from arkindex_worker import logger
from arkindex_worker.cache import create_tables, init_cache_db, merge_parents_cache
from arkindex_worker.cache import (
create_tables,
init_cache_db,
merge_parents_cache,
retrieve_parents_cache_path,
)
def _is_500_error(exc):
@@ -137,12 +142,17 @@ class BaseWorker(object):
self.secrets = {name: self.load_secret(name) for name in required_secrets}
task_id = os.environ.get("PONOS_TASK")
task = None
paths = None
if self.support_cache and self.args.database is not None:
self.use_cache = True
elif self.support_cache and task_id:
task = self.request("RetrieveTaskFromAgent", id=task_id)
self.use_cache = len(task["parents"]) > 0
paths = retrieve_parents_cache_path(
task["parents"],
data_dir=os.environ.get("PONOS_DATA", "/data"),
chunk=os.environ.get("ARKINDEX_TASK_CHUNK"),
)
self.use_cache = len(paths) > 0
if self.use_cache:
if self.args.database is not None:
@@ -161,13 +171,8 @@ class BaseWorker(object):
logger.debug("Cache is disabled")
# Merging parents caches (if there are any) in the current task local cache, unless the database got overridden
if self.use_cache and self.args.database is None and task:
merge_parents_cache(
task["parents"],
self.cache_path,
data_dir=os.environ.get("PONOS_DATA", "/data"),
chunk=os.environ.get("ARKINDEX_TASK_CHUNK"),
)
if self.use_cache and self.args.database is None and paths is not None:
merge_parents_cache(paths, self.cache_path)
def load_secret(self, name):
"""Load all secrets described in the worker configuration"""
Loading