From cf0527f9c72b5b7c764384754c4493984c9f3de1 Mon Sep 17 00:00:00 2001 From: Tim McCormack Date: Tue, 31 Oct 2023 12:11:12 -0400 Subject: [PATCH] feat: Log addition of config watchers and make receivers unique (#487) - Add log message for each model the ConfigWatcher is listening to, mostly so I can tell whether this app is even getting loaded. - Add dispatch_uid to receivers so that if `ready` (or `connect_receivers`) is called more than once, the receiver is only attached once. (This is not a response to an observed problem -- it's just a best practice according to Django docs.) --- CHANGELOG.rst | 9 +++++++++ edx_arch_experiments/__init__.py | 2 +- edx_arch_experiments/config_watcher/signals/receivers.py | 6 ++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b8a8214..6c447b5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,15 @@ Change Log Unreleased ~~~~~~~~~~ +[3.1.0] - 2023-10-31 +~~~~~~~~~~~~~~~~~~~~ + +Changed +_______ + +* Add log message for each model the ConfigWatcher is listening to +* Ensure that ConfigWatcher only attaches receivers once + [3.0.0] - 2023-10-30 ~~~~~~~~~~~~~~~~~~~~ diff --git a/edx_arch_experiments/__init__.py b/edx_arch_experiments/__init__.py index 04cb836..1d15ee0 100644 --- a/edx_arch_experiments/__init__.py +++ b/edx_arch_experiments/__init__.py @@ -2,4 +2,4 @@ A plugin to include applications under development by the architecture team at 2U. """ -__version__ = '3.0.0' +__version__ = '3.1.0' diff --git a/edx_arch_experiments/config_watcher/signals/receivers.py b/edx_arch_experiments/config_watcher/signals/receivers.py index 1e3a436..c03f2bc 100644 --- a/edx_arch_experiments/config_watcher/signals/receivers.py +++ b/edx_arch_experiments/config_watcher/signals/receivers.py @@ -99,7 +99,7 @@ def _register_waffle_observation(*, model, short_name, fields): short_name (str): A short descriptive name for an instance of the model, e.g. "flag" fields (list): Names of fields to report on in the Slack message """ - @receiver(signals.post_save, sender=model) + @receiver(signals.post_save, sender=model, dispatch_uid=f"config_watcher_{short_name}_change") def report_waffle_change(*args, instance, created, **kwargs): try: _report_waffle_change(short_name, instance, created, fields) @@ -107,13 +107,15 @@ def report_waffle_change(*args, instance, created, **kwargs): # Log and suppress error so Waffle change can proceed log.exception(f"Failed to report change to waffle {short_name}") - @receiver(signals.post_delete, sender=model) + @receiver(signals.post_delete, sender=model, dispatch_uid=f"config_watcher_{short_name}_delete") def report_waffle_delete(*args, instance, **kwargs): try: _report_waffle_delete(short_name, instance) except: # noqa pylint: disable=bare-except log.exception(f"Failed to report deletion of waffle {short_name}") + log.info(f"Watching {model.__module__}.{model.__qualname__} for changes") + def connect_receivers(): """