I'm having application built using celery and recently we got a requirement to run certain tasks on schedule.
I think celerybeat is perfect for this, but I got few questions:
- Is it possible to run multiple celerybeat instances, so that tasks are not duplicated?
- How to make sure that celerybeat is always up & running?
So far I read this: https://github.com/celery/celery/issues/251 and https://github.com/ybrs/single-beat
It looks like a single instance of celerybeat should be running.
I'm running application inside AWS elasticbeanstalk docker containers and celery workers are also docker containers (so it's quickly scaleable when needed).
It would be best to have celerybeat run through supervisord along with celery workers, but it seems this is not proper way to do this.
At the same time having that single instance of celerybeat would require manual provision/start and monitoring.
You may run multiple instances of celery beat and tasks will not be duplicated.
Take a look at the celery.beat.Scheduler class, specifically the reserve() function. The scheduler will reserve a task before submitting it to the grid for execution. This prevents another instance of celery beat from submitting the same task.
We use MongoDB as a backing store for our scheduled tasks. Here is a sample document showing that the task has been reserved by one of the schedulers.
http://celery.readthedocs.org/en/latest/reference/celery.beat.html#celery.beat.Scheduler
I just found this solution as celery-beat replacement: RedBeat, blog post
Didn't use it yet though.
To answer your 2 questions:
If you run several celerybeat instances you get duplicated tasks, so afaik you should have only single celerybeat instance.
I'm using
supervisord
as you mentioned to run celery workers and celerybeat workers as deamon so they should always be up & running.my supervisord config: