edx-platform
edx-platform copied to clipboard
Do not clear cache when running eager tasks
Description
When the CELERY_ALWAYS_EAGER
setting variable is True
celery tasks are run in the same thread as the Django Request. As a result, code that is intended to cleanup the celery worker inadvertently clears the RequestCache.
**Update: ** There are times in which we may want to run celery eagerly and still clear the cache, such as testing. I have reverted the logic in _clear_request_cache
back to only check CLEAR_REQUEST_CACHE_ON_TASK_COMPLETION
as original, and instead have set CLEAR_REQUEST_CACHE_ON_TASK_COMPLETION = False
in all dev and test environments that already have CELERY_ALWAYS_EAGER = True
. The unit test that specifically tests whether the request cache is getting cleared upon completion of a celery task then overrides CLEAR_REQUEST_CACHE_ON_TASK_COMPLETION = True
even though CELERY_ALWAYS_EAGER = True
for the sake of that specific testing purpose.
Supporting information
The issue and its resolution are discussed here.
Testing instructions
Run the platform using the devstack/test/bokchoy settings files, or simply defining CELERY_ALWAYS_EAGER = True
. Confirm that the RequestCache is not cleared each time a celery task is triggered with apply_sync
.
Deadline
None
Other information
None
Thanks for the pull request, @jcohen28! 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.
@jcohen28 Even though your pull request wasn’t merged, please take a moment to answer a two question survey so we can improve your experience in the future.