Reputation: 5465
In celery 4> the periodic_task
decorator is deprecated. The recommendation now is to define every periodic task inside where you initialize celery (based on what I can find, and the docs).
In my django setup, I have a lot of small apps, and having a central place to setup period tasks won't do it.
I am still learning my way around celery, but I think my solution is "good".
Is this the wrong way to solve this, or is there another way now that periodic_task
is gone?
from celery.schedules import crontab
from lib.celery_instance import app # The celery instance
@app.task()
def mytask():
# do something...
return 123
app.add_periodic_task(crontab(hour=8, minute=45), mytask.s())
Upvotes: 0
Views: 528
Reputation: 2022
Another approach to centrally manage the periodic tasks could be to define a dict in the settings.
CELERY_BEAT_SCHEDULE = {
'some name': {
'task': 'myapp.tasks.do_something',
'schedule': crontab(hour=0, minute=0),
}
}
Upvotes: 1