Skip to content

Commit

Permalink
fixup! various
Browse files Browse the repository at this point in the history
- Expand module docstring a bit
- Remove outdated comment
- Correct setting annotation (copy-paste error)
- Clarify get_producer docstring (since it caches)
- Annotate infinite loop as NoReturn
  • Loading branch information
timmc-edx committed Nov 18, 2022
1 parent bcb2e8f commit a5cedbe
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions openedx_events/event_bus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Classes and utility functions for the event bus.
This module includes the entry points for the producer and consumer.
API:
- ``get_producer`` returns an ``EventBusProducer`` singleton that should be used for sending all events
Expand Down Expand Up @@ -42,7 +44,6 @@ def _try_load(*, setting_name: str, args: tuple, kwargs: dict, expected_class: t
constructor_path = getattr(settings, setting_name, None)
if constructor_path is None:
warnings.warn(f"Event Bus setting {setting_name} is missing; component will be inactive.", UserWarning)
# No warning is called for if event-bus is not configured-for at *all*
return default

try:
Expand Down Expand Up @@ -100,12 +101,12 @@ def send(
# called. The format of the string is a dotted path to an attribute in a module, e.g.
# ``some.module.path.EventBusImplementation``. This producer will be managed as a singleton
# by openedx_events. If setting is not supplied or the callable raises an exception or does not return
# an instance of EventBusConsumer, calls to the consumer will be ignored with a warning at startup.
# an instance of EventBusProducer, calls to the producer will be ignored with a warning at startup.

@lru_cache # will just be one cache entry, in practice
def get_producer() -> EventBusProducer:
"""
Create the producer implementation, as configured.
Create or retrieve the producer implementation, as configured.
If misconfigured, returns a fake implementation that can be called but does nothing.
"""
Expand All @@ -121,7 +122,7 @@ class EventBusConsumer(ABC):
"""

@abstractmethod
def consume_indefinitely(self):
def consume_indefinitely(self) -> NoReturn:
"""
Consume events from a topic in an infinite loop.
Expand All @@ -134,7 +135,7 @@ class NoEventBusConsumer(EventBusConsumer):
Stub implementation to "load" when no implementation is properly configured.
"""

def consume_indefinitely(self):
def consume_indefinitely(self) -> NoReturn:
"""Do nothing."""


Expand Down

0 comments on commit a5cedbe

Please sign in to comment.