Is it possible to empty a job queue on a Gearman server

11,231

Solution 1

As far as i have been able to tell from the docs and using gearman with PHP, the only way to clear the job queue is to restart to the gearmand job server. If you are using persistent job queues, you will also need to empty whatever you are using as the persistent storage, if this is DB storage, you will need to empty the appropriate tables of all the rows.

stop gearmand --> empty table rows --> start gearmand

Hope this is clear enough.

Solution 2

I came across this method:

/usr/bin/gearman -t 1000 -n -w -f function_name > /dev/null

which basically dumps all the jobs into /dev/null.

Solution 3

The telnetable administrative protocol (search for "Administrative Protocol") doesn't have a command to empty a queue either, there is only a shutdown command.

If you wish to avoid downtime, you could write a generic "job consumer" worker and use that to empty the queues. I've set one up as a script which takes a list of job names, and just sits there accepting jobs and consuming them.

Something like:

# generic_consumer.py job1 job2 job3

You can use the administrative protocol's status command to get a list of the function names and counts on the queue. The administrative protocol docs tell you the format of the response.

# (echo status ; sleep 0.1) | netcat 127.0.0.1 4730
Share:
11,231
daniyalzade
Author by

daniyalzade

Eytan (@daniyalzade) went to Stanford University, where he received a BS ('07) and MS ('08) in Electrical Engineering. He realized that startups were the way to go, after working at not so starting-up companies, McKinsey and Microsoft. He then, worked as early engineer at Adap.tv, a rapidly growing video ad exchange, and Chartbeat, an awesome company focusing on real-time analytics and making people care about data. When he finds spare time, he likes playing squash, skiing and running; and he dearly misses his windsurfing days in San Francisco.

Updated on June 14, 2022

Comments

  • daniyalzade
    daniyalzade about 2 years

    Is it possible to empty a job queue on a Gearman server? I am using the python driver for Gearman, and the documentation does not have any information about emptying queues. I would imagine that this functionality should exist, possibly, with a direct connection to the Gearman server.

  • daniyalzade
    daniyalzade over 13 years
    it's unfortunate that they don't have a purge command. just to lay it out there, the other open source message queue server RabbitMQ has this command
  • James Butler
    James Butler over 13 years
    Yes, its a quite annoying problem but i think a few people might be working on a patch to allow the concept of job removal from the queue.