From ef08a8be5339b99fcab94fd6abd21705ef0c7e0d Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 25 Dec 2021 15:41:09 +0100 Subject: [PATCH] actionsmap: add global flag to disable cache and lock --- moulinette/actionsmap.py | 6 +++++- moulinette/core.py | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index 8f68a2f6..0b1eb9d7 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -414,6 +414,9 @@ class ActionsMap(object): # Read actions map from yaml file actionsmap = read_yaml(actionsmap_yml) + if not actionsmap["_global"].get("cache", True): + return actionsmap + # Delete old cache files for old_cache in glob.glob(f"{actionsmap_yml_dir}/.{actionsmap_yml_file}.*.pkl"): os.remove(old_cache) @@ -536,7 +539,7 @@ class ActionsMap(object): full_action_name = "%s.%s.%s" % (namespace, category, action) # Lock the moulinette for the namespace - with MoulinetteLock(namespace, timeout): + with MoulinetteLock(namespace, timeout, self.enable_lock): start = time() try: mod = __import__( @@ -618,6 +621,7 @@ class ActionsMap(object): _global = actionsmap.pop("_global", {}) self.namespace = _global["namespace"] + self.enable_lock = _global.get("lock", True) self.default_authentication = _global["authentication"][ interface_type ] diff --git a/moulinette/core.py b/moulinette/core.py index 785cbeec..65eb396c 100644 --- a/moulinette/core.py +++ b/moulinette/core.py @@ -291,10 +291,11 @@ class MoulinetteLock(object): base_lockfile = "/var/run/moulinette_%s.lock" - def __init__(self, namespace, timeout=None, interval=0.5): + def __init__(self, namespace, timeout=None, enable_lock=True, interval=0.5): self.namespace = namespace self.timeout = timeout self.interval = interval + self.enable_lock = enable_lock self._lockfile = self.base_lockfile % namespace self._stale_checked = False @@ -421,7 +422,7 @@ class MoulinetteLock(object): return False def __enter__(self): - if not self._locked: + if self.enable_lock and not self._locked: self.acquire() return self