Hassan Baig
Hassan Baig

Reputation: 15844

Celery beat scheduling option to immediately launch task upon celery launch

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?

Upvotes: 0

Views: 377

Answers (1)

Hassan Baig
Hassan Baig

Reputation: 15844

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.

Upvotes: 0

Related Questions