0

I have a docker-compose.yml file that defines a number of services. One is a redis instance, and another is a queue-worker.

The queue-worker fetches jobs from redis and performs the necessary work.

Currently, I have the queue-worker's stop_grace_period set to 5m, within my docker-compose.yml. The idea here is that when I run docker-compose down, the queue-worker will have 5 minutes to deal with any remaining jobs in the queue, before shutting down.

I would like to improve the situation, if possible, by performing a check when docker-compose down is called. If the result of the check is true, e.g. curl http://project/total-jobs-in-queue == 0 then go ahead and stop the queue-worker container immediately. If the result is false, i.e. there are still jobs in the work queue, delay container shutdown until the result of the check is true.

I could write a bash script to perform this check, and shut the containers individually, from within the script, however if it was possible to configure this in such a way that the standard docker-compose up/down commands could continue to be used, that would be much more preferable.

Is this possible?

Scratcha
  • 1,359
  • 1
  • 14
  • 22
  • I do not understand. `stop the container immediately` Just exit the process that is running. – KamilCuk Feb 13 '23 at 19:45
  • I don't want the ```queue-worker``` container to stop if there is still work in the queue. – Scratcha Feb 13 '23 at 20:25
  • Is that `queue-worker` a program _you_ have written and have control over? – KamilCuk Feb 13 '23 at 20:25
  • Yes. It's a python script running in a linux shell / python environment. – Scratcha Feb 13 '23 at 20:30
  • 1
    So handle the SIGTERM signal in your python script and terminate your script when that condition is satisfied. `stop_grace_period` is about delay between SIGTERM and SIGKILL. You script receives SIGTERM, so terminate it gracefully as fast as posisble. – KamilCuk Feb 13 '23 at 20:43
  • Not possible on docker/docker-compose configuration level. You have to do a script for that, you can make it a while loop with sleep script or a cron job, depends on other factors. But anyway, you will need a custom way – Rafael Zerbini Feb 13 '23 at 20:43

0 Answers0