Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: [FC-0074] add more detailed concepts on events #406

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dcee8c9
docs: update documentation references
mariajgrimaldi Oct 10, 2024
f1d6e17
fix: add missing references for links
mariajgrimaldi Oct 15, 2024
7432fd9
docs: clarify events-vs-filters.rst
mariajgrimaldi Oct 15, 2024
1fdec22
docs: remove unused references
mariajgrimaldi Oct 15, 2024
655fa5e
docs: Update openedx-events.rst
mariajgrimaldi Oct 15, 2024
9b2b76d
fix: remove trailing spaces
mariajgrimaldi Oct 15, 2024
572b98c
docs: remove linebreaks to improve rendering
mariajgrimaldi Oct 15, 2024
0c144a0
fix: use correct reference for signal handler
mariajgrimaldi Oct 15, 2024
29ec64f
docs: add reference to how-to use open edx events
mariajgrimaldi Oct 15, 2024
570f2b0
fix: use relative path for how-tos folder
mariajgrimaldi Oct 15, 2024
479ff67
fix: use html file extension for reference
mariajgrimaldi Oct 15, 2024
4ab1d11
docs: address PR reviews
mariajgrimaldi Oct 21, 2024
f7b2d3f
docs: Update hooks-extension-framework.rst
mariajgrimaldi Oct 21, 2024
5390db7
docs: Update hooks-extension-framework.rst
mariajgrimaldi Oct 21, 2024
a76715b
docs: Update openedx-events.rst
mariajgrimaldi Oct 21, 2024
f089f1d
docs: Update openedx-events.rst
mariajgrimaldi Oct 21, 2024
c62cca0
docs: Update openedx-events.rst
mariajgrimaldi Oct 21, 2024
1ea6988
refactor: address reviews
mariajgrimaldi Oct 28, 2024
9978c33
docs: add why using the framework section
mariajgrimaldi Oct 28, 2024
c7cba6f
docs: be consistent with framework name
mariajgrimaldi Oct 28, 2024
e0bf02a
fix: add correct reference to handler
mariajgrimaldi Oct 28, 2024
54b7299
fix: remove trailing space
mariajgrimaldi Oct 28, 2024
97074af
refactor!: drop duplicated documents in favor of centralized docs
mariajgrimaldi Oct 31, 2024
6926b20
refactor: address PR reviews
mariajgrimaldi Nov 4, 2024
4497dff
fix: correctly reference send method from django signals
mariajgrimaldi Nov 4, 2024
2ed1f05
refactor: use double backticks instead of single
mariajgrimaldi Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions docs/concepts/hooks-extension-framework.rst

This file was deleted.

2 changes: 1 addition & 1 deletion docs/concepts/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Concepts
:maxdepth: 1
:caption: Contents:

hooks-extension-framework
openedx-events
69 changes: 69 additions & 0 deletions docs/concepts/openedx-events.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Open edX Events
===============

Overview
--------

Open edX Events provide a mechanism for extending the platform by enabling developers to listen to Open edX-specific Django signals emitted by various services and respond accordingly. This allows for customized reactions to actions or changes within the platform without modifying the Open edX platform codebase, with the main goal of minimizing maintenance efforts for the Open edX project and plugin maintainers.

What are Open edX Events?
-------------------------

Open edX Events are signals emitted by a service (e.g., LMS, CMS, or others) within the Open edX ecosystem to notify that an action has occurred. For example, a user may have registered, logged in, or created a course.

These events are built on top of Django signals, inheriting their behavior while also incorporating metadata and actions specific to the Open edX ecosystem, making them uniquely suited for Open edX. Since they are essentially Django signals tailored to Open edX's specific needs, we can refer to `Django Signals Documentation`_ for a more detailed understanding of Open edX Events:

Django includes a "signal dispatcher" which helps decoupled applications get notified when actions occur elsewhere in the framework. In a nutshell, signals allow certain senders to notify a set of receivers that some action has taken place. They’re especially useful when many pieces of code may be interested in the same events.

Events are primarily used as a communication method between components within the same application process or with external services using the `Event Bus technology`_, making them the standard communication mechanism within the Open edX ecosystem.

How do Open edX Events work?
mariajgrimaldi marked this conversation as resolved.
Show resolved Hide resolved
----------------------------

Open edX Events are implemented by a class called `OpenEdxPublicSignal`_, which inherits from `Django's Signals class` and adds behaviors specific to the Open edX ecosystem. Thanks to this design, ``OpenEdxPublicSignal`` leverages the functionality of Django signals, allowing developers to apply their existing knowledge of the Django framework.

The event execution process follows these steps:

#. An application component emits an event by calling the `send_event` method implemented by `OpenEdxPublicSignal`_.

#. The class generates Open edX-specific metadata for the event on the fly, like the event version or the timestamp when the event was sent. The event receivers use this metadata during their processing.

#. The tooling uses the `send or send_robust`_ method from Django signals under the hood. The ``send`` method is used for development and testing, while the ``send_robust`` method is used in production to ensure receivers don't raise exceptions halting the application process.

#. Building on Django signals allows us to use the same `Django signals registry mechanism`_ for receiver management. This means that developers can register `signal receivers in their plugins`_ for Open edX Events in the same way they would for Django signals.

#. The event is sent to all registered receivers, which are executed in the order they were registered. Each receiver processes the event data and performs the necessary actions.

#. After all receivers for the event have been executed, the process continues with the application logic.

Here is an example of an event that saves a user's notification preferences when they enroll in a course:

#. A user enrolls in a course, `triggering the COURSE_ENROLLMENT_CREATED event`_. This event includes information about the user, course, and enrollment details.

#. A signal receiver listening for the ``COURSE_ENROLLMENT_CREATED`` event is called and processes the event data. In this case, it would be the `course_enrollment_post_save receiver`_.

#. The signal receiver creates a notification preference for the user, enabling them to receive notifications about the course.

#. The application continues with the course enrollment process.

The `Django Signals Documentation`_ provides a more detailed explanation of how Django signals work.

How are Open edX Events used?
-----------------------------

Developers can listen to Open edX Events by registering signal receivers from their Open edX Django plugins that respond to the emitted events. This is done using Django's signal mechanism, which allows developers to listen for events and execute custom logic in response.

For more information on using Open edX Events, refer to the `Using Open edX Events`_ how-to guide.

.. _Using Open edX Events: ../how-tos/using-events.html
.. _Django Signals Documentation: https://docs.djangoproject.com/en/4.2/topics/signals/
.. _triggering the COURSE_ENROLLMENT_CREATED event: https://github.com/openedx/edx-platform/blob/master/common/djangoapps/student/models/course_enrollment.py#L777-L795
.. _course_enrollment_post_save receiver: https://github.com/openedx/edx-platform/blob/master/openedx/core/djangoapps/notifications/handlers.py#L38-L53
.. _Event Bus technology: https://openedx.atlassian.net/wiki/spaces/AC/pages/3508699151/How+to+start+using+the+Event+Bus
.. _Django signals registry mechanism: https://docs.djangoproject.com/en/4.2/topics/signals/#listening-to-signals
.. _signal receivers in their plugins: https://edx.readthedocs.io/projects/edx-django-utils/en/latest/edx_django_utils.plugins.html#edx_django_utils.plugins.constants.PluginSignals
.. _Open edX Django plugins: https://edx.readthedocs.io/projects/edx-django-utils/en/latest/plugins/readme.html
.. _OpenEdxPublicSignal: https://github.com/openedx/openedx-events/blob/main/openedx_events/tooling.py#L37
.. _Django's Signals class: https://docs.djangoproject.com/en/4.2/topics/signals/#defining-and-sending-signals
.. _send_event: https://github.com/openedx/openedx-events/blob/main/openedx_events/tooling.py#L185
.. _send or send_robust: https://docs.djangoproject.com/en/4.2/topics/signals/#sending-signals