ruby-on-railsresquegod

Graceful way to restart resque workers


Is there a graceful way to restart resque workers(say after an event like deploy) where the worker which was processing some job from the queue doesn't get killed by a signal like SIGTERM or SIGKILL immediately, rather it should wait for the worker to finish the task it's doing and kill the worker when it gets free.

I am using God to monitor the resque workers and I went through the God homepage but wasn't able to find any info on the same but seeing as it's just a gem to monitor processes I don't think it has a graceful way to do this.

Also, I am looking to do automatic worker restart on deploy, I have looked at these two methods(http://simonecarletti.com/blog/2011/02/how-to-restart-god-when-you-deploy-a-new-release/, http://balazs.kutilovi.cz/2011/12/04/deploying-resque-scheduler-with-capistrano/). If there is a better way, it would be much helpful.


Solution

  • Turns out resque has an option where if you pass the signal SIGQUIT it will wait for the worker to finish the job and then quit the worker and god has an option of setting a stop signal for the process. So, you can define 'QUIT' as the stop_signal for the resque workers and when you stop god, it will send the singal SIGQUIT to the worker.