When I wanted to run a celery task, I got an error:
from config import celery_app
@celery_app.task(name="task_name")
def my_task():
return
ImportError: cannot import name 'celery_app' from 'config' (/Users/matthieuchabert/Documents/workspace/stockpro/code/transfer/backend/config/__init__.py)
Expected behavior
According to the Celery documentation, we need to add the code below to the file {{project_name}}/__init__.py
from __future__ import absolute_import, unicode_literals
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ('celery_app',)
Description
When I wanted to run a celery task, I got an error:
Expected behavior According to the Celery documentation, we need to add the code below to the file
{{project_name}}/__init__.py
I added it, and now it's working properly.