Skip to content

Commit 37d9ae8

Browse files
committed
✨(backend) force loading celery shared task in libraries
Library we are using can have celery shared task. We have to make some modification to load them earlier when the celery app is configure and when the impress app is loaded.
1 parent 29ea6b8 commit 37d9ae8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/backend/impress/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Impress package. Import the celery app early to load shared task form dependencies."""
2+
3+
from .celery_app import app as celery_app
4+
5+
__all__ = ["celery_app"]

src/backend/impress/celery_app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
install(check_options=True)
1313

14+
# Can not be loaded only after install call.
15+
from django.conf import settings # pylint: disable=wrong-import-position
16+
1417
app = Celery("impress")
1518

1619
# Using a string here means the worker doesn't have to serialize
@@ -20,4 +23,4 @@
2023
app.config_from_object("django.conf:settings", namespace="CELERY")
2124

2225
# Load task modules from all registered Django apps.
23-
app.autodiscover_tasks()
26+
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

0 commit comments

Comments
 (0)