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

fix: avoid infinite recursion of openedx-event #312

Merged
merged 2 commits into from
Feb 12, 2024

Conversation

Ian2012
Copy link
Contributor

@Ian2012 Ian2012 commented Feb 9, 2024

Description: This PR adds a new argument from_event_bus to the send_event method (and related ones) that allows marking a Django signal as already processed from the event bus and avoids infinite emission of the same signal if such signal is consumed in the same runtime.

The following code block must be used on the consumer to avoid processing the signal in the same process that emitted the signal:

from openedx_events.tooling import SIGNAL_PROCESSED_FROM_EVENT_BUS

...

def my_signal(...):
    if not kwargs.get(SIGNAL_PROCESSED_FROM_EVENT_BUS, False):
        logger.info("Event received from a non-event bus backend, skipping...")
        return

This has been tested with the event-bus-redis without any changes as the behavior of calling send_event_with_custom_metadata is to enable the from_event_bus param. Tested on openedx/event-routing-backends#361 with the signal emitted on openedx/event-tracking#246

ISSUE: Solves: #79

Testing instructions:

Merge checklist:

  • All reviewers approved
  • CI build is green
  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed

Post merge:

  • Create a tag
  • Check new version is pushed to PyPI after tag-triggered build is
    finished.
  • Delete working branch (if not needed anymore)

Author concerns: List any concerns about this PR - inelegant
solutions, hacks, quick-and-dirty implementations, concerns about
migrations, etc.

@Ian2012 Ian2012 requested a review from a team as a code owner February 9, 2024 19:11
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Feb 9, 2024
@openedx-webhooks
Copy link

Thanks for the pull request, @Ian2012! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

openedx_events/apps.py Outdated Show resolved Hide resolved
@Ian2012 Ian2012 force-pushed the cag/avoid-infinite-recursion branch from b18b09f to c6c3182 Compare February 9, 2024 20:01
Copy link
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few no-blocking comments! Thank you

openedx_events/apps.py Outdated Show resolved Hide resolved
openedx_events/apps.py Outdated Show resolved Hide resolved
@bmtcril bmtcril requested a review from robrap February 9, 2024 20:23
@mariajgrimaldi
Copy link
Member

The next release with these changes will affect the event bus implementation tooling, so I'm pinging @robrap @timmc-edx so they know. Thanks!

@Ian2012
Copy link
Contributor Author

Ian2012 commented Feb 12, 2024

The next release with these changes will affect the event bus implementation tooling, so I'm pinging @robrap @timmc-edx so they know. Thanks!

@mariajgrimaldi it will not affect them as event-bus-redis and event-bus-kafka already call send_event_with_custom_metadata on receiving signals from the event bus. There doesn't exist a signal that is produced/consumed on the same runtime (except this current work: openedx/event-routing-backends#361) and this PR makes the default behavior to mark the signal when calling such a method.

Copy link
Contributor

@timmc-edx timmc-edx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few notes. Also remember to update version and changelog.

openedx_events/apps.py Outdated Show resolved Hide resolved
openedx_events/tooling.py Outdated Show resolved Hide resolved
openedx_events/tooling.py Outdated Show resolved Hide resolved
@Ian2012
Copy link
Contributor Author

Ian2012 commented Feb 12, 2024

@timmc-edx rebased and bumped. Do you think is ready to be merged? cc @mariajgrimaldi

openedx_events/apps.py Outdated Show resolved Hide resolved
Copy link
Contributor

@timmc-edx timmc-edx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor issue, but looks great overall!

Copy link
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Thanks. I'll merge after @Ian2012 addresses the last comment.

chore: quality fixes

fix: mark signals as already emitted by event bus automatically

test: update test with from_event_bus

chore: address suggestion

test: implement tests

chore: quality fixes

chore: address suggestion

test: correct tests

chore: update debug log for signal processing from event bus

Co-authored-by: Tim McCormack <tmccormack@edx.org>

chore: handle pr comments

chore: handle pr comments
@mariajgrimaldi mariajgrimaldi merged commit 3211a4f into openedx:main Feb 12, 2024
8 checks passed
@openedx-webhooks
Copy link

@Ian2012 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants