Skip to content

Commit

Permalink
feat: add consumer for tracking event emitted signal
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Jun 5, 2023
1 parent 37a0814 commit 51656fa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions event_routing_backends/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
This module contains various configuration settings via
waffle switches for the Certificates app.
"""

from edx_toggles.toggles import SettingToggle, WaffleSwitch


# .. toggle_name: SEND_TRACKING_EVENT_EMITTED_SIGNAL
# .. toggle_implementation: SettingToggle
# .. toggle_default: False
# .. toggle_description: When True, the system will publish `TRACKING_EVENT_EMITTED` signals to the event bus. The
# `TRACKING_EVENT_EMITTED` signal is emit when a tracking log is emitted.
# .. toggle_use_cases: publish
SEND_TRACKING_EVENT_EMITTED_SIGNAL = SettingToggle('SEND_TRACKING_EVENT_EMITTED_SIGNAL', default=False, module_name=__name__)
23 changes: 23 additions & 0 deletions event_routing_backends/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.dispatch import receiver

from openedx_events.analytics.signals import TRACKING_EVENT_EMITTED
from openedx_events.event_bus import get_producer

from event_routing_backends.config import SEND_TRACKING_EVENT_EMITTED_SIGNAL

@receiver(TRACKING_EVENT_EMITTED)
def listen_for_certificate_created_event(sender, signal, **kwargs):
"""
Publish `TRACKING_EVENT_EMITTED` events to the event bus.
"""
print("\n\n", "listen_for_certificate_created_event", "\n\n")
print("\n\n", kwargs, "\n\n")

if SEND_TRACKING_EVENT_EMITTED_SIGNAL.is_enabled():
get_producer().send(
signal=TRACKING_EVENT_EMITTED,
topic='analytics',
event_key_field='tracking_log.name',
event_data={'tracking_log': kwargs['tracking_log']},
event_metadata=kwargs['metadata']
)

0 comments on commit 51656fa

Please sign in to comment.