Open edX Events Tooling#
Here we document the tooling available for working with Open edX events as a developer.
- class openedx_events.tooling.OpenEdxPublicSignal(event_type, data, minor_version=0)[source]#
Standardized Django Signals used to create Open edX events.
- allow_send_event_failure()[source]#
Allow Django signal to fail. Meaning, uses send_robust instead of send.
More information on send_robust in the Django official documentation.
- generate_signal_metadata(time=None)[source]#
Generate signal metadata when an event is sent.
These fields are generated on the fly and are a subset of the Event Message defined in the OEP-41.
- Parameters:
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:
>>> metadata = STUDENT_REGISTRATION_COMPLETED.generate_signal_metadata() attr.asdict(metadata) >>> { 'event_type': '...learning.student.registration.completed.v1', 'minorversion': 0, 'time': '2021-06-09T14:12:45.320819Z', 'source': 'openedx/lms/web', 'sourcehost': 'edx.devstack.lms', 'specversion': '1.0', 'sourcelib: (0,1,0,), }
- classmethod get_signal_by_type(event_type)[source]#
Get event identified by type.
- Parameters:
event_type (str) – name of the event.
- Raises:
Raises KeyError if the event is not found. –
- send(sender, **kwargs)[source]#
Override method used to recommend the sender to adopt our custom send.
- send_event(send_robust=True, time=None, **kwargs)[source]#
Send events to all connected receivers.
Used to send events just like Django signals are sent. In addition, some validations are executed on the arguments, and then generates relevant metadata that can be used for logging or debugging purposes. Besides this behavior, send_event behaves just like the send method.
If the event is disabled (i.e _allow_events is False), then this method won’t have any effect. Meaning, the Django Signal won’t be sent.
- Example usage:
>>> STUDENT_REGISTRATION_COMPLETED.send_event( user=user_data, registration=registration_data, ) >>> [(<function callback at 0x7f2ce638ef70>, 'callback response')]
- Parameters:
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 the event’s data.
- Returns:
- response of each receiver following the format [(receiver, response), … ].
The list is empty if the event is disabled.
- Return type:
list
- Raises:
SenderValidationError – raised when there’s a mismatch between arguments passed to this method and arguments used to initialize the event.
- send_event_with_custom_metadata(metadata, /, *, send_robust=True, **kwargs)[source]#
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.- Parameters:
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_eventdocstring for more details.
Maintenance chart
Review Date |
Reviewer |
Release |
Test situation |
2025-02-05 |
Maria Grimaldi |
Sumac |
Pass. |