Stopping gearman workers nicely

Viewed 15635

I have a number of Gearman workers running constantly, saving things like records of user page views, etc. Occasionally, I'll update the PHP code that is used by the Gearman workers. In order to get the workers to switch to the new code, I the kill and restart the PHP processes for the workers.

What is a better way to do this? Presumably, I'm sometime losing data (albeit not very important data) when I kill one of those worker processes.

Edit: I found an answer that works for me, and posted it below.

12 Answers

Hmm, You could implement a code in the workers to check occasionally if the source code was modified, if yes then just just kill themselves when they see fit. That is, check while they are in the middle of the job, and if job is very large.

Other way would be implement some kind of an interrupt, maybe via network to say stop whenever you have the chance and restart.

The last solution is helping to modify Gearman's source to include this functionality.

This would fit nicely into your continuous integration system. I hope you have it or you should have it soon :-)

As you check in new code, it automatically gets built and deployed onto the server. As a part of the build script, you kill all workers, and launch new ones.

Related