Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delay a task using Celery?

Not talking about the delay method.

I want to be able to get a task, given it's task_id and change it's ETA on the fly, before it is executed.

For now I have to cancel it, and re-schedule one. Troublesome if the scheduled process involve a lot of stuff.

like image 901
e-satis Avatar asked Jul 28 '10 21:07

e-satis


2 Answers

You should store some 'pause' value outside of celery/task queue. I do this with a mailer using celery. I can pause parts of the system by setting values in either memcache or mysql. The tasks then make sure to query the outside resource before executing the task. If it's meant to be paused it sets it does a task.retry() that causes it to go through the retry delay time and such.

like image 72
Rick Avatar answered Sep 20 '22 22:09

Rick


Assuming you are using django-celery and PeriodicTask with DatabaseScheduler, you need to modify your PeriodicTask interval or crontab and save it. If your task is defined by an interval, modify the last_run_at property.

You run celerybeat with the database scheduler with:

python manage.py celerybeat -S djcelery.schedulers.DatabaseScheduler
like image 36
Antoine Martin Avatar answered Sep 17 '22 22:09

Antoine Martin