Skip to content

Commit

Permalink
chore: quality fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Feb 9, 2024
1 parent ac0b58a commit 9ab4173
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion openedx_events/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

from openedx_events.event_bus import get_producer
from openedx_events.exceptions import ProducerConfigurationError
from openedx_events.tooling import OpenEdxPublicSignal, load_all_signals, SIGNAL_PROCESSED_FROM_EVENT_BUS
from openedx_events.tooling import SIGNAL_PROCESSED_FROM_EVENT_BUS, OpenEdxPublicSignal, load_all_signals

logger = logging.getLogger(__name__)


def general_signal_handler(sender, signal, **kwargs): # pylint: disable=unused-argument
"""
Signal handler for producing events to configured event bus.
Expand Down
18 changes: 15 additions & 3 deletions openedx_events/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ def _send_event_with_metadata(self, metadata, send_robust=True, from_event_bus=F
Arguments:
metadata (EventsMetadata): The metadata to be sent with the signal.
send_robust (bool): Defaults to True. See Django signal docs.
from_event_bus (bool): Defaults to False. If True, the signal is
being sent from the event bus. This is used to prevent infinite
loops when the event bus is consuming events. It should not be
used when sending events from the application.
See ``send_event`` docstring for more details on its usage and behavior.
"""
Expand Down Expand Up @@ -165,7 +169,7 @@ def validate_sender():
validate_sender()

kwargs["metadata"] = metadata
kwargs[SIGNAL_PROCESSED_FROM_EVENT_BUS]= from_event_bus
kwargs[SIGNAL_PROCESSED_FROM_EVENT_BUS] = from_event_bus

if self._allow_send_event_failure or settings.DEBUG or not send_robust:
return super().send(sender=None, **kwargs)
Expand Down Expand Up @@ -215,7 +219,9 @@ def send_event(self, send_robust=True, from_event_bus=False, time=None, **kwargs
the event.
"""
metadata = self.generate_signal_metadata(time=time)
return self._send_event_with_metadata(metadata=metadata, send_robust=send_robust, from_event_bus=from_event_bus, **kwargs)
return self._send_event_with_metadata(
metadata=metadata, send_robust=send_robust, from_event_bus=from_event_bus, **kwargs
)

def send_event_with_custom_metadata(
self, metadata, /, *, send_robust=True, from_event_bus=False, **kwargs
Expand All @@ -232,12 +238,18 @@ def send_event_with_custom_metadata(
Arguments:
metadata (EventsMetadata): The metadata to be sent with the signal.
send_robust (bool): Defaults to True. See Django signal docs.
from_event_bus (bool): Defaults to False. If True, the signal is
being sent from the event bus. This is used to prevent infinite
loops when the event bus is consuming events. It should not be
used when sending events from the application.
kwargs: Data to be sent to the signal's receivers.
See ``send_event`` docstring for more details.
"""
return self._send_event_with_metadata(metadata=metadata, send_robust=send_robust, from_event_bus=from_event_bus, **kwargs)
return self._send_event_with_metadata(
metadata=metadata, send_robust=send_robust, from_event_bus=from_event_bus, **kwargs
)

def send(self, sender, **kwargs): # pylint: disable=unused-argument
"""
Expand Down

0 comments on commit 9ab4173

Please sign in to comment.