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.
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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With