I have a docker compose that contains the following stack: django application, rabbitmq, celery beat (master) and celery workers (agents).
When I want to deploy a new deployment of the docker compose I need to kill the former containers, and I want to find a way to do it with out killing a celery worker in the middle of a task. Basiclly I want my CD job to be able to wait until the celery worker is not running a task before we kill the container.
I thought about maybe:
- Killing the celery beat container
- Monitoring the amount of running processes running in the celery worker container and once it hits 0 to kill the container.
The main issue is that the killing the celery beat container is not enough for the celery worker container to pull new tasks, since it is possible that more tasks were queued in the rabbitmq before I killed the celery beat container, and while the rabbitmq is up and the celery worker is up it can pull new tasks directly from the rabbitmq.
I thought about maybe killing the rabbitmq container as well, but I think it won't be good because we might not have dataloss, but it my result in long downtime.
How do you suggest to handle this issue with no dataloss and minimal down time?
Thank you!