Skip to content

Commit

Permalink
refactor: follow google style docstring convention instead
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajgrimaldi committed Jan 15, 2025
1 parent 095c5b8 commit 98aabc3
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions openedx_events/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def __init__(self, event_type, data, minor_version=0):
Init method for OpenEdxPublicSignal definition class.
Arguments:
- event_type (str): name of the event.
- data (dict): attributes passed to the event.
- minor_version (int): version of the event type.
event_type (str): name of the event.
data (dict): attributes passed to the event.
minor_version (int): version of the event type.
"""
self.init_data = data
self.event_type = event_type
Expand Down Expand Up @@ -79,10 +79,10 @@ def get_signal_by_type(cls, event_type):
Get event identified by type.
Arguments:
- event_type (str): name of the event.
event_type (str): name of the event.
Raises:
- Raises KeyError if the event is not found.
Raises KeyError if the event is not found.
"""
return cls._mapping[event_type]

Expand All @@ -94,7 +94,7 @@ def generate_signal_metadata(self, time=None):
Message defined in the OEP-41.
Arguments:
- time (datetime): (Optional) Timestamp when the event was sent with
time (datetime): (Optional) Timestamp when the event was sent with
UTC timezone. Defaults to current time in UTC. See OEP-41 for more details.
Example usage:
Expand Down Expand Up @@ -124,9 +124,9 @@ def _send_event_with_metadata(self, metadata, send_robust=True, from_event_bus=F
This method is for internal use only.
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
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.
Expand Down Expand Up @@ -200,24 +200,22 @@ def send_event(self, send_robust=True, time=None, **kwargs):
>>> [(<function callback at 0x7f2ce638ef70>, 'callback response')]
Arguments:
- send_robust (bool): Defaults to True. See Django signal docs.
- time (datetime): (Optional - see note) Timestamp when the event was
sent with UTC timezone. For events requiring a DB create or
update, use the timestamp from the DB record. Defaults to
current time in UTC. This argument is optional for backward
compatibility, but ideally would be explicitly set. See OEP-41
for details.
send_robust (bool): Defaults to True. See Django signal docs.
time (datetime): (Optional - see note) Timestamp when the event was sent with UTC
timezone. For events requiring a DB create or update, use the timestamp from the DB
record. Defaults to current time in UTC. This argument is optional for backward
compatibility, but ideally would be explicitly set. See OEP-41 for details.
Keyword Arguments:
- kwargs: Data to be sent to the signal's receivers. The keys must match the attributes defined in
kwargs: Data to be sent to the signal's receivers. The keys must match the attributes defined in
the event's data.
Returns:
- list: response of each receiver following the format [(receiver, response), ... ].
list: response of each receiver following the format [(receiver, response), ... ].
The list is empty if the event is disabled.
Raises:
- SenderValidationError: raised when there's a mismatch between arguments passed
SenderValidationError: raised when there's a mismatch between arguments passed
to this method and arguments used to initialize the event.
"""
metadata = self.generate_signal_metadata(time=time)
Expand All @@ -230,18 +228,17 @@ def send_event_with_custom_metadata(
Send events to all connected receivers using the provided metadata.
This method works exactly like ``send_event``, except it uses the given
event metadata rather than generating it. This is used by the
event bus consumer, where we want to recreate the metadata used
in the producer when resending the same signal on the consuming
side.
event metadata rather than generating it. This is used by the
event bus consumer, where we want to recreate the metadata used
in the producer when resending the same signal on the consuming
side.
Arguments:
metadata (EventsMetadata): The metadata to be sent with the signal.
send_robust (bool): Defaults to True. See Django signal docs.
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=True, **kwargs
Expand Down

0 comments on commit 98aabc3

Please sign in to comment.