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

Merged
merged 26 commits into from
Nov 25, 2024
Merged
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
7a96f57
docs: update documentation references
mariajgrimaldi Oct 10, 2024
ffb64da
fix: add missing references for links
mariajgrimaldi Oct 15, 2024
9dfd3a3
docs: clarify events-vs-filters.rst
mariajgrimaldi Oct 15, 2024
36f6aa8
docs: remove unused references
mariajgrimaldi Oct 15, 2024
27bf392
docs: Update openedx-events.rst
mariajgrimaldi Oct 15, 2024
49ae1af
fix: remove trailing spaces
mariajgrimaldi Oct 15, 2024
a6c3e63
docs: remove linebreaks to improve rendering
mariajgrimaldi Oct 15, 2024
a4c55a7
fix: use correct reference for signal handler
mariajgrimaldi Oct 15, 2024
e415b70
docs: add reference to how-to use open edx events
mariajgrimaldi Oct 15, 2024
9791b5b
fix: use relative path for how-tos folder
mariajgrimaldi Oct 15, 2024
b58de56
fix: use html file extension for reference
mariajgrimaldi Oct 15, 2024
6b11976
docs: address PR reviews
mariajgrimaldi Oct 21, 2024
95d72d4
docs: Update hooks-extension-framework.rst
mariajgrimaldi Oct 21, 2024
88640cc
docs: Update hooks-extension-framework.rst
mariajgrimaldi Oct 21, 2024
9869fb7
docs: Update openedx-events.rst
mariajgrimaldi Oct 21, 2024
a455a1e
docs: Update openedx-events.rst
mariajgrimaldi Oct 21, 2024
f6b9640
docs: Update openedx-events.rst
mariajgrimaldi Oct 21, 2024
cb44992
refactor: address reviews
mariajgrimaldi Oct 28, 2024
4b33fe2
docs: add why using the framework section
mariajgrimaldi Oct 28, 2024
4550d6d
docs: be consistent with framework name
mariajgrimaldi Oct 28, 2024
44f930d
fix: add correct reference to handler
mariajgrimaldi Oct 28, 2024
83816cc
fix: remove trailing space
mariajgrimaldi Oct 28, 2024
7428b89
refactor!: drop duplicated documents in favor of centralized docs
mariajgrimaldi Oct 31, 2024
baff218
refactor: address PR reviews
mariajgrimaldi Nov 4, 2024
15c2540
fix: correctly reference send method from django signals
mariajgrimaldi Nov 4, 2024
1656d67
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