1

I'm new to Gearman, but I understand the general concepts. I realize that this isn't something that you would normally want to do... But I was wondering if there is a way to send a "job" to ALL workers?

I have a script that monitors my workers and respawns them when they die. I would like to be able to send out a job that says "die," when I want to kill / respawn all worker processes.

Is this possible? Thanks!

tambler
  • 3,009
  • 2
  • 23
  • 26
  • To send a message to the vast majority of German workers, consider advertising in the [nation's leading tabloid.](http://www.bild.de/) `(end mandatory lame German/Gearman joke)` – Pekka Oct 05 '11 at 15:41

1 Answers1

1

There are a couple of ways that you can go about this.

The easiest way is to send the "kill" job for every worker that you have. Once they've all been killed, then respawn them. The downside of this method is that you will have to wait until all your workers are dead before you can begin respawning. If you existing script respawns immediately, you'll run into problems here.

Another method is to register a unique task for each of your workers. If, for example, you have two workers, register a task "kill_001" for the first worker, and "kill_002" for the second worker. To kill your workers, determine the unique jobs to start ("kill_001", "kill_002"), and then send them out. Respawned workers should have new unique tasks, i.e. don't register a new job "kill_001" if it hasn't been killed yet. Although this method can require a bit more work, it will allow you to respawn your workers without downtime.

thetaiko
  • 7,816
  • 2
  • 33
  • 49
  • Thanks! The problem mentioned in your first paragraph is not something I had considered. I am very interested in implementing your second option, as that sound like a much better route. – tambler Oct 05 '11 at 15:58
  • Is it possible to query Gearman for a list of "unique" functions that are available to call? How would I go about determining the unique ID's? Would prefer not to have to use another persistent storage mechanism to store references to available functions, but maybe I will have to. Is it possible to do this without having to go that route? – tambler Oct 05 '11 at 15:59
  • Again, there are various ways to go about this. The PECL Gearman extension doesn't let you query for the list of available tasks. Gearman itself will let you, though. See [an example here](http://stackoverflow.com/questions/2752431/any-way-to-access-gearman-administration). Retrieve a list of the kill tasks, and then use a sequence or random number generator and assign new tasks that don't collide. No persistent storage required. – thetaiko Oct 05 '11 at 16:04