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

feat: utility to reset application state before processing event #277

Merged

Conversation

navinkarkera
Copy link
Contributor

@navinkarkera navinkarkera commented Oct 13, 2023

Description: Adds utility function to reset application state which can be used by event bus implementation to reset request/db_connection before processing events.

ISSUE: openedx/event-bus-redis#49

Related:

Reviewers:

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.

@navinkarkera navinkarkera self-assigned this Oct 13, 2023
@navinkarkera navinkarkera requested a review from a team as a code owner October 13, 2023 06:44
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Oct 13, 2023
@openedx-webhooks
Copy link

openedx-webhooks commented Oct 13, 2023

Thanks for the pull request, @navinkarkera! 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.

RequestCache.clear_all_namespaces()


def prepare_for_new_work_cycle():
Copy link
Member

Choose a reason for hiding this comment

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

@navinkarkera looking at this PR I see that the new utility function is added but not executed anywhere.
If so, that means that it is the signal handler that must explicitly call this prepare_for_new_work_cycle function. Am I understanding the intent correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@felipemontoya Yes, that is correct. Have created a draft PR: openedx/event-bus-redis#56 in event bus redis to use this utility.

Copy link
Contributor

Choose a reason for hiding this comment

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

This may be a good time to move https://openedx.atlassian.net/wiki/spaces/AC/pages/3662643205/How+to+add+a+new+concrete+implementation+of+the+event+bus to this repo and to update any incoming links to that doc to point to the newer version of the doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@robrap Done, we can update the incoming links once this PR is merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

@navinkarkera: Were you still planning on updating the links?

@navinkarkera navinkarkera force-pushed the navin/work-cycle-utility branch 4 times, most recently from f91067d to 26e9aec Compare October 16, 2023 14:50

The consumer class then needs to implement ``consume_indefinitely`` loop, which will stay running and listen to events as they come in.

If you are doing this within Django, one thing to be aware of is Django will not do any of the automatic connection cleanup that it usually does per request. This means that if your database restarts while the ``consume_indefinitely`` loop is running, Django may try to hold on to a defunct connection. To address this, we have included an `utility function <../../openedx_events/tooling.py#L323>`_ in openedx-events which needs to called before processing any signal. Checkout `consumer.py <https://github.com/openedx/event-bus-redis/blob/main/edx_event_bus_redis/internal/consumer.py>`_ in event bus redis implementation. We’re also resetting the RequestCache in the utility function, and there may be later, more comprehensive changes..
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: update links in follow up PR

Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

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

Thanks for bringing in the doc.

docs/how-tos/add-new-implementation.rst Outdated Show resolved Hide resolved
docs/how-tos/add-new-implementation.rst Outdated Show resolved Hide resolved
docs/how-tos/add-new-implementation.rst Outdated Show resolved Hide resolved
openedx_events/__init__.py Outdated Show resolved Hide resolved
@robrap robrap added the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Dec 5, 2023
@robrap
Copy link
Contributor

robrap commented Dec 5, 2023

@navinkarkera: This PR has been sitting for a couple of months. Do you intend to return to this? It would be great to get it landed. Thank you!

@navinkarkera
Copy link
Contributor Author

@robrap Apologies, I got caught up with some other projects. I'll surely get this done within this week.

@navinkarkera
Copy link
Contributor Author

@robrap Thanks for your patience. Addressed your comments. Please have a look.

@mphilbrick211 mphilbrick211 removed the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Dec 11, 2023
@robrap
Copy link
Contributor

robrap commented Dec 11, 2023

Thanks @navinkarkera and @mphilbrick211. This is on my list, but I've got a long list and lots of days off, so this may take me a little time to get to.

Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

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

Thanks @navinkarkera. It looks like your fixup commit added requirements updates. Can we drop those changes from the PR, or do you need that for some reason? Other than that, this is ready to squash as-needed.

docs/how-tos/add-new-event-bus-concrete-implementation.rst Outdated Show resolved Hide resolved
@navinkarkera
Copy link
Contributor Author

It looks like your fixup commit added requirements updates. Can we drop those changes from the PR, or do you need that for some reason?

@robrap Actually, we added edx_django_utils to requirements as we need RequestCache for our new utility function.

Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

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

Sorry @navinkarkera. Would you mind just updating the date? Then I'll merge. Thanks.

CHANGELOG.rst Outdated
@@ -14,6 +14,12 @@ Change Log
Unreleased
----------

[9.3.0] - 2023-12-08
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
[9.3.0] - 2023-12-08
[9.3.0] - 2024-01-04

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@robrap Apologies for the delay. Updated the date.

@robrap
Copy link
Contributor

robrap commented Feb 2, 2024

@navinkarkera: Apologies, but I totally spaced on merging this, and now it has conflicts. I'm sorry about that. If we get it up-to-date net week I will merge as soon as you tell me it is ready. Thank you!

chore: bump version and update changelog

chore: remove utility function from coverage

docs: move how to add new implementation doc from atlassian

docs: simplify consuming docs in how-to
@edx-requirements-bot edx-requirements-bot merged commit 33cd7d5 into openedx:main Feb 7, 2024
8 checks passed
@openedx-webhooks
Copy link

@navinkarkera 🎉 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 Ready to Merge
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants