Skip to content

Fire events from openedx_content so that downstream effects can be handled in platform #462

Closed

Description

@kdmccormick

Background

In other words: it should be safe to call openedx_content directly, rather than be forced to go through xblock_api and libraries_api, and expect that the openedx_content events will be sufficient for edx-platform to manage any downstream effects.

The specific thing that brought this to our attention was libraries indexing. If you call openedx_content directly, then you are allowed to edit library content within Learning Core, but it will not trigger the necessary reindexing within edx-platform. So, we have been forced to create wrapper APIs in edx-platform within the content_libraries_api.
It would be better if the content_libraries_api was only needed for Libraries-specific things (creating a library, renaming library) and that all content operations could safely be done via the openedx_content, triggering events which the content_libraries app would catch and use as a signal to begin reindexing the affected content.

AC

  • Define openedx-events for component and container authoring
    • Delete
    • Publish
    • Create/Edit (batched by DraftChangeLog)
    • Collection operations
  • Fire those events from the openedx_content function calls
  • Consume the events in the content_libraries app and reindex content as appropriate
  • Consume and react to any other events as appropriate
  • Take into account existing events that need to be re-fired based on these new Learning Core events. Hypotheticals:
    • xblock_created
    • xblock_updated
    • library_block_updated
    • library_block_published ??
    • etc...
      DEPR the ones that are non-batch.
      Where possible, populate event data from LC rather than by invoking the XBlock runtime.
  • As appropriate, move functions from libraries_api down into xblock_api and openedx_content, and/or remove unnecessary libraries_api wrapper functions. Update existing references.

Notes/questions

  • For content edit events, each one should be fired upon commit of the entire DraftChangeLog, not each DraftChangeLogEntry. This way, we get one event per batched edit of entities, rather than one event per entity.

  • Other than reindexing, are there any other instances of handling these events that we think we'll need for Libraries?

  • When we have Courses in Learning Core, the Publish event will be used for many many things. Currently, we catch COURSE_PUBLISHED and have a huge handler that does a lot of things (proctored exam registration, due dates, block transformers, outline generation). As we move to LC, we'll want to move to doing more-scoped recomputation based on these events.

    • Need example of "more scoped event handling"

Activity

  1. kdmccormick commented on Jun 24, 2025

    @kdmccormick
    MemberAuthor

    FYI @bradenmacdonald -- as we discussed in Slack

  2. bradenmacdonald commented on Jun 25, 2025

    @bradenmacdonald
    Contributor

    Thanks for writing this up @kdmccormick !

  3. changed the title [-]Fire events from authoring_api to trigger library reindexing[/-] [+]Fire events from authoring_api so that downstream effects can be handled in edx-platform[/+] on Jan 20, 2026
  4. changed the title [-]Fire events from authoring_api so that downstream effects can be handled in edx-platform[/-] [+]Fire events from `openedx_content` so that downstream effects can be handled in edx-platform[/+] on Jan 30, 2026
  5. changed the title [-]Fire events from `openedx_content` so that downstream effects can be handled in edx-platform[/-] [+]Fire events from `openedx_content` so that downstream effects can be handled in platform[/+] on Jan 30, 2026
  6. bradenmacdonald commented on Apr 2, 2026

    @bradenmacdonald
    Contributor

    Doing some analysis of the existing events and how they work:

    Authoring Events Specific to Libraries

    Libraries do not have a "duplicate component" action, so there is no "duplicate" event. Copying and pasting a block results in both LIBRARY_BLOCK_CREATED and LIBRARY_BLOCK_UPDATED, which may come out of order (UPDATED then CREATED).

    Authoring Events Specific to Courses

    Note: creating a new course results in: COURSE_CREATED, COURSE_CATALOG_INFO_CHANGED x4, XBLOCK_UPDATED (course xblock) x2, XBLOCK_CREATED (course_info xblock). Weirdly, I don't see an XBLOCK_CREATED for the course root block.

    Note: creating a new Section results in: XBLOCK_CREATED (chapter block) and COURSE_CATALOG_INFO_CHANGED (?). Similar events are emitted for creating a subsection. But creating a unit only emits XBLOCK_CREATED, and is not considered a catalog change.

    Authoring Events (General)

    General Comments

    Most of the existing events attach very little data to the event. So little in fact, that I question how useful they are.

    For example, XBLOCK_UPDATED has only usage_key, block_type (which could be trivially derived from usage_key), and version. (The version field is problematic for several reasons: it's optional, it's actually an opaque key so should be called versioned_usage_key, it puts the version info in the key which we want to move away from, it only states the new version not the old version, and it doesn't actually work - in my testing, it was always equal to usage_key).

    When a library XBlock has changed, the LIBRARY_BLOCK_UPDATED event essentially has only the usage_key of the updated block, but no other information (it has the library_key but you can derived that from usage_key anyways).

    Same with the LIBRARY_BLOCK_PUBLISHED event - it has only the usage key, and no information about what changed.

    The weird exception is the COURSE_CATALOG_INFO_CHANGED event, which provides a relatively large and detailed event payload:

    {
        'signal': <authoring.course.catalog_info.changed.v1>,
        'sender': None,
        'catalog_info': CourseCatalogData(
            course_key=CourseLocator('OpenCraftX', 'NC', '26', None, None),
            name='A New Course',
            schedule_data=CourseScheduleData(
                start=datetime.datetime(2030, 1, 1, 0, 0, tzinfo=...),
                pacing='instructor',
                end=None,
                enrollment_start=None,
                enrollment_end=None
            ),
            hidden=False,
            invitation_only=False
        ),
        'metadata': EventsMetadata(...),
        'from_event_bus': False
    }
  7. bradenmacdonald commented on Apr 2, 2026

    @bradenmacdonald
    Contributor

    @kdmccormick @ormsbee

    I think I have two big open questions about event handling in openedx-core at the moment:

    1. Mapping from Learning Package -> high level concepts.

    We can emit low-level events like COMPONENT_UPDATED, with details like learning_package_id, component_id, component_type_namespace (e.g. xblock), component_type (e.g. video),old_version, new_version. But for practical purposes, consumers of these events will want an XBLOCK_UPDATED_v2 event that includes the Learning Context ID and the usage key.

    The problem is that Open edX Core has no way to map from Learning Package to Learning Context at the moment. For Content Libraries, it's not so hard as the relationship is either 1:0 or 1:1, and it's a simple lookup in the ContentLibraries table, but that data is currently only at the platform level, not in openedx_content. So one option is to make openedx-platform listen for low-level COMPONENT_CHANGED events and then re-emit them as high level LIBRARY_BLOCK_UPDATED or XBLOCK_UPDATED_V2 events. Another option is to move the core library model(s) into openedx-core.

    For Components that are in courses (theoretical), I'm not sure how we're supposed to handle this. If we have several course runs sharing a learning package, I'm not sure what mechanism we plan to have for determining which course run a given component belongs to.

    2. Batching

    The AC for this issue seems to be encouraging us to move toward batched events where 1 event contains many IDs of changed objects. We can do this because of our nice DraftChangeLog, PublishLog, etc.

    But:

    • By their nature, batched events usually need to be received/consumed by a task that processes them in a celery worker.
    • In the past, we've had many use cases where we edit a single item and we want to wait synchronously for its related handlers to finish processing (e.g. we save an XBlock, we want to update the search index and then mark the save as done and return a 200 response to the browser, which expects the search index to be up to date).
    • So, we previously concluded "we recommend that simple handlers are synchronous and the sender of the event should send the event(s) from an async celery task if it is expected to result in a lot of handlers being called."
    • In other words, emit lots of small, specific events rather than one big batch event, and emit the events asynchronously if they're part of a big batch of changes. This allows specific use cases like publishing a single block to incorporate synchronous event handlers, while still being performant for bigger changes.

    So: I don't think that moving to "only batched" events is the way to go, but if we do want to have batched events, and I think we probably should, it might make sense to have a low-level batched event that also emits N smaller, detailed events. e.g. an ENTITIES_PUBLISHED batch event for a group of a dozen changes that leads to a dozen singular XBLOCK_PUBLISHED events (which are emitted async if there's > 1, or sync if there's <= 1). As long as there's some way for some actions on single objects to be synchronous and bulk actions to be asynchronous.

  8. kdmccormick commented on Apr 3, 2026

    @kdmccormick
    MemberAuthor

    Thanks a bunch for the discovery work @bradenmacdonald .

    The problem is that Open edX Core has no way to map from Learning Package to Learning Context at the moment. For Content Libraries, it's not so hard as the relationship is either 1:0 or 1:1, and it's a simple lookup in the ContentLibraries table, but that data is currently only at the platform level, not in openedx_content. So one option is to make openedx-platform listen for low-level COMPONENT_CHANGED events and then re-emit them as high level LIBRARY_BLOCK_UPDATED or XBLOCK_UPDATED_V2 events. Another option is to #515 (comment).
    For Components that are in courses (theoretical), I'm not sure how we're supposed to handle this. If we have several course runs sharing a learning package, I'm not sure what mechanism we plan to have for determining which course run a given component belongs to.

    This is tricky. In the ~Willow timeframe, I think it would make a lot sense to:

    • move the index in to openedx_content so it can be used by systems other than Libraries
    • move Libraries into openedx-core
    • make openedx-core aware of Contexts, Usages, and their keys

    but I'm not sure which of those, if any, we could do well by Verawood, especially without having designed Courses for openedx-core yet.

    A critical question in designing this will be "Does openedx-core know about XBlocks?". I assume we want that to be "no", but this means refactoring APIs and deciding what the boundary between "Usages"/"Components" (openedx-core) and "XBlocks" (openedx-platform) is, and what the relationship between Usages and Components is.

    So: I don't think that moving to "only batched" events is the way to go, but if we do want to have batched events, and I think we probably should, it might make sense to have a low-level batched event that also emits N smaller, detailed events. e.g. an ENTITIES_PUBLISHED batch event for a group of a dozen changes that leads to a dozen singular XBLOCK_PUBLISHED events (which are emitted async if there's > 1, or sync if there's <= 1). As long as there's some way for some actions on single objects to be synchronous and bulk actions to be asynchronous.

    Yeah, great point. @ormsbee and I talked today and arrived at a similar conclusion. This might actually be enough to get us to Verawood-- imagine a handful of simple batched events: LEARNING_PACKAGE_ENTITIES_CHANGED, LEARNING_PACKAGE_ENTITIES_PUBLISHED, LEARNING_PACKAGE_COLLECTIONS_CHANGED. openedx-platform could listen to those events instead of the single-block events, and, with the help of the changelogs, both update the Meili index and emit the existing single-block events for backwards compatibilty.

    What do you think @bradenmacdonald ?

  9. bradenmacdonald commented on Apr 6, 2026

    @bradenmacdonald
    Contributor

    @kdmccormick Yes, I think something like that makes a lot of sense for Verawood. My only hesitation is that if we end up going in a different direction for Willow, we'll have a lot of different noisy events that we need to keep emitting for backwards compatibility.

  10. kdmccormick commented on Apr 6, 2026

    @kdmccormick
    MemberAuthor

    we'll have a lot of different noisy events that we need to keep emitting for backwards compatibility.

    are you thinking those batched LEARNING_PACKAGES_* events, or those existing *BLOCK* events?

    I actually feel pretty solid about the former events as a long-term contract, but let's talk in sync tomorrow to confirm.

    I feel less solid about the latter events. But, I don't think we'd be committing to supporting them any more than we are now, we'd just be maintaining the existing behavior.

  11. bradenmacdonald commented on Apr 6, 2026

    @bradenmacdonald
    Contributor

    those batched LEARNING_PACKAGES_* events

    These we may want to change depending on how one maps from learning package to context. But if these are always just low level events being re-emitted, then I guess they'd be pretty stable indeed.

    those existing BLOCK events

    Yeah, I think those ones aren't so useful (very little info in them), are under-specified (in what contexts do they get emitted), and aren't future compatible (with non-xblock components like xPLA) but they're also pretty easy to continue supporting so maybe not a big deal.

  12. kdmccormick commented on Apr 7, 2026

    @kdmccormick
    MemberAuthor

    Notes

    ENTITIES_CHANGED events

    • should we include draftchangelog or just its pk?
    • listeners will probably want to listen for specific things: video changed, problem changed, etc.
    • having the info in the event will prevent listeners from having to load every draftchangelog
    • and also not all listeners will have access to the draftchangelog table
    • things we could include
      • what changed
      • who changed it
      • old and new version numbers
    • event which lives in openedx-events repo, or put it in openedx-core repo ? the latter would assume that listeners are in-process--could just be a regular django signal, as oex-signals are just subclasses of django signals so the conversion is easier later.
    • events will be pretty useless without the learning context info (we should eventually move context into core so that the events can have it), so we may as well emit them as django signals
      • also probably include container_type, container_code, component_type, component_code
  13. bradenmacdonald commented on Apr 16, 2026

    @bradenmacdonald
    Contributor

    I have implemented a fully-working LEARNING_PACKAGE_ENTITIES_CHANGED event in #543 . Please take a look if you have a moment.

  14. bradenmacdonald commented on Apr 17, 2026

    @bradenmacdonald
    Contributor

    Should deleting a learning package send out two batch events indicating that all the entities in that learning package have been deleted, and that deletion has been "published"? Or would that be problematic if the event handlers try to load any data when handling the event? Or do we not care, since deleting a learning package is not part of the official API.

  15. bradenmacdonald commented on Apr 29, 2026

    @bradenmacdonald
    Contributor

    This is done! Though I left tagging events unimplemented for now and proposed a plan for them in #557 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions