phpgearman

How can I get the number of queued jobs of a particular type in gearman?


I have a number of gearman clients sending a job, say job1.

$client = new GearmanClient();
$client->addServer();
$client->doBackground('job1', 'workload');

It takes, say 10 seconds to process this job. I want to track how many 'job1' jobs are waiting for a worker to work on them at any given time. How can I do that?


Solution

  • For quick checking, I use this bash one-liner:

    (echo status ; sleep 0.1) | netcat 127.0.0.1 4730
    

    This opens a connection to a gearman instance running on localhost, and sends the status query. This contains the name and number of jobs on that instance. The information can then be processed with grep/awk/wc etc. for reporting and alerting.

    I also do the same with the workers query which shows all connected workers.

    (echo workers ; sleep 0.1) | netcat 127.0.0.1 4730
    

    The sleep is to keep the connection open long enough for the reply.

    The full list of administrative commands, and what the output means is at http://gearman.org/protocol/. Just search for "Administrative Protocol".