Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all Gearman jobs from the Gearman Job Server

Is there a way to remove all Gearman jobs from the Gearman Job Server? I have a PHP application that runs Gearman jobs in the background. For my unit tests I need to ensure that a) there are no jobs waiting for a worker that executes it and b) that there is no worker working. The latter is not that important because it is easy to kill the workers but the former--I don't know how to implement this.

like image 872
stofl Avatar asked Aug 16 '11 12:08

stofl


1 Answers

Removing all jobs of single type

Use the following command (just replace FUNCTION_NAME):

gearman -n -w -f FUNCTION_NAME > /dev/null

To remove only n number of jobs add -c n param, i.e. to remove 20 jobs:

gearman -c 20 -n -w -f FUNCTION_NAME > /dev/null


Removing all jobs from server

If you want to remove all jobs, run the following loop:

for MATCH in $(echo status | nc 127.0.0.1 4730 | grep -v \\. |  grep -Pv '^[^\t]+\t0\t' | cut -s -f 1-2 --output-delimiter=\,); 
do 
    gearman -n -w -f ${MATCH%\,*} -c ${MATCH#*\,} > /dev/null;
done

Replace 127.0.0.1 4730 with your gearmand server address and port.

ps: removing jobs from persistent storage (i.e. sqlite) will not remove them from gearmand until it is restarted (because gearmand process has in-memory cache)

like image 186
Artur Bodera Avatar answered Sep 22 '22 14:09

Artur Bodera