How to I call a celery (app) task from the project level and vice versa.
I have a Django directory structure like:
- proj
|_ celery.py
|_ settings.py
- app
|_ tasks.py
|_ views.py
In settings.py I have a CELERYBEAT_SCHEDULE var which refers to a shared_task in app/tasks
. This task is not listed in celery inspect registered
.
Neither are tasks which are listed in the registry since they were defined in proj/celery.py
, callable by functions in apps/views.py
.
I've followed the instructions on the celery website.
Functions in the shared_task decorator must be listed in the apps AppConfig.
Under app/apps.py
import your task like so:
from .tasks import add
In app/tasks.py
import shared_task like so:
from proj.celery import shared_task
In proj/celery.py
import shared_task like so:
import celery
from celery import shared_task
Pycharm will complain about unused imports, however they are used, just not in the file pycharm is parsing.
Now when I start celery worker like:
python manage.py celeryd --loglevel=DEBUG &
rather than
celery -A pears worker --loglevel=info &
My tasks in app/tasks.py
are registered and callable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With