This is not a question, but help for those who find that declaring periodic tasks described in celery 4.0.1 documentation is difficult to integrate into django: http://docs.celeryproject.org/en/latest/userguide/periodic-tasks. html # entries
copy the celery config folder to main_app/celery.py :
from celery import Celery from celery.schedules import crontab app = Celery() @app.on_after_configure.connect def setup_periodic_tasks(sender, **kwargs):
Question
But what if we use django and our tasks are placed in another application? With celery 4.0.1 , we no longer have the @periodic_task decorator. So let's see what we can do.
First case
If you prefer to keep tasks and their schedule close to each other:
main_app/some_app/tasks.py
from main_app.celery import app as celery_app @celery_app.on_after_configure.connect def setup_periodic_tasks(sender, **kwargs):
We can run beat in debug mode:
celery -A main_app beat -l debug
and we will see that there is no such periodic task.
Second case
We can try to describe all periodic tasks in the configuration file as follows:
main_app/celery.py
... app = Celery() @app.on_after_configure.connect def setup_periodic_tasks(sender, **kwargs):
The result is the same. But it will behave differently, which you can see with manual debugging via pdb. In the first setup_periodic_tasks example setup_periodic_tasks callback will not be run at all. But in the second example, we get django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. (this exception will not be printed)
python django celery
vvkuznetsov
source share