(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.
This commit is contained in:
Manuel Raynaud
2025-05-05 15:36:36 +02:00
parent 29ea6b8ef7
commit 37d9ae8cca
2 changed files with 9 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
"""Impress package. Import the celery app early to load shared task form dependencies."""
from .celery_app import app as celery_app
__all__ = ["celery_app"]

View File

@@ -11,6 +11,9 @@ os.environ.setdefault("DJANGO_CONFIGURATION", "Development")
install(check_options=True)
# Can not be loaded only after install call.
from django.conf import settings # pylint: disable=wrong-import-position
app = Celery("impress")
# Using a string here means the worker doesn't have to serialize
@@ -20,4 +23,4 @@ app = Celery("impress")
app.config_from_object("django.conf:settings", namespace="CELERY")
# Load task modules from all registered Django apps.
app.autodiscover_tasks()
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)