Skip to content

Commit

Permalink
feat: Log addition of config watchers and make receivers unique (#487)
Browse files Browse the repository at this point in the history
- 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.)
  • Loading branch information
timmc-edx authored Oct 31, 2023
1 parent 4c1dda6 commit cf0527f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion edx_arch_experiments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
6 changes: 4 additions & 2 deletions edx_arch_experiments/config_watcher/signals/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,23 @@ 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)
except: # noqa pylint: disable=bare-except
# 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():
"""
Expand Down

0 comments on commit cf0527f

Please sign in to comment.