-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce a Celery singleton across cms and lms by using shared module (#…
…25840) This should prevent the issues we've seen recently where cms modules are imported by the running lms process, resulting in two celery instances being created and tasks intermittently being registered to the wrong instance (and therefore effectively lost.) In commit ab6bf34/PR #25822 we tried to ensure that only one or the other of the instances was created by adding a startup check. Unfortunately, there's an external shared library that refers directly to the lms celery, causing a startup failure in cms, so we had to revert it. Rather than waiting to fix that library, this commit collapses the two instances together so that there is only ever one.
- Loading branch information
Showing
5 changed files
with
42 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Instantiate the singleton Celery instance that is used by either lms or cms. | ||
WARNING: Do not import this module directly! | ||
This module should only be imported by cms.celery and lms.celery, which perform | ||
setup in a particular order before and after Celery is instantiated. Otherwise, | ||
it might be possible for the Celery singleton to be created without variant- | ||
specific configuration. | ||
The module is intended as a way to have a Celery singleton shared between cms | ||
and lms code. Not having a guaranteed singleton means that it is possible for | ||
each of cms and lms to instantiate Celery, and tasks may be nondeterministically | ||
registered to one or the other of the instances and therefore sometimes lost | ||
to the running process. The root ``__init__.py``s of cms and lms both ensure that | ||
this module is loaded when any cms or lms code runs, effectively using the | ||
Python module system as a singleton loader. (This is an incremental improvement | ||
over older code, and there is probably a better mechanism to be had.) | ||
""" | ||
|
||
from celery import Celery | ||
|
||
# WARNING: Do not refer to this unless you are cms.celery or | ||
# lms.celery. See module docstring! | ||
APP = Celery('proj') | ||
|
||
APP.conf.task_protocol = 1 | ||
# Using a string here means the worker will not have to | ||
# pickle the object when using Windows. | ||
APP.config_from_object('django.conf:settings') | ||
APP.autodiscover_tasks() |