Celery beat scheduling option to immediately launch task upon celery launch

378 views Asked by At

I can schedule an hourly task in my Django app using celery beat in settings.py like so:

CELERYBEAT_SCHEDULE={
'tasks.my_task':{
'task':'tasks.my_task',
'schedule':timedelta(seconds=60*60),
'args':(),
},
}

But is there a way to schedule a task such that it immediately queues up and is calculated, thereafter following the configured schedule from there on? E.g., something like executing a selected task instantly at celery launch. What's the configuration for that?

1

There are 1 answers

0
Hassan Baig On

Add the following to tasks.py:

obj = locals()['task_function_name']
obj.run()

This ensures the specified task is run when celery is run. Thereafter, it executes according to schedule.