summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleš Mrázek <ales.mrazek@nic.cz>2024-12-27 16:05:51 +0100
committerAleš Mrázek <ales.mrazek@nic.cz>2025-01-14 09:48:01 +0100
commit251a59ae85883035c0fe4792577e9d600b6d5ce8 (patch)
tree508c497f164bf2a128cedeac6812ad2640468a63
parentmanager: files: added files_reload callback (diff)
downloadknot-resolver-251a59ae85883035c0fe4792577e9d600b6d5ce8.tar.xz
knot-resolver-251a59ae85883035c0fe4792577e9d600b6d5ce8.zip
manager: config_store: added only_on_no_changes_update decorator
This decorator will only trigger the function if the selected config has not been changed.
-rw-r--r--python/knot_resolver/manager/config_store.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/python/knot_resolver/manager/config_store.py b/python/knot_resolver/manager/config_store.py
index 214062b2..70a9d942 100644
--- a/python/knot_resolver/manager/config_store.py
+++ b/python/knot_resolver/manager/config_store.py
@@ -59,6 +59,25 @@ class ConfigStore:
return self._config
+def only_on_no_changes_update(selector: Callable[[KresConfig], Any]) -> Callable[[UpdateCallback], UpdateCallback]:
+ def decorator(orig_func: UpdateCallback) -> UpdateCallback:
+ original_value_set: Any = False
+ original_value: Any = None
+
+ async def new_func_update(config: KresConfig) -> None:
+ nonlocal original_value_set
+ nonlocal original_value
+ if not original_value_set:
+ original_value_set = True
+ elif original_value == selector(config):
+ await orig_func(config)
+ original_value = selector(config)
+
+ return new_func_update
+
+ return decorator
+
+
def only_on_real_changes_update(selector: Callable[[KresConfig], Any]) -> Callable[[UpdateCallback], UpdateCallback]:
def decorator(orig_func: UpdateCallback) -> UpdateCallback:
original_value_set: Any = False