Programmatically get the number of jobs in a Resque queue

I am interested in setting up a monitoring service that will send me pages when there are too many jobs in the Resque queue (I have about 6 queues, I will have different numbers for each queue). I also want to set up a very similar monitoring service that will alert me when I exceed a certain number of failed jobs in my queue.

My question is that there are a lot of keys and confusion that I see related to Resque on my redis server. I don’t necessarily see a direct way to get the number of jobs in the queue or the number of failed jobs. Is there currently a trivial way to capture this data from redis?

+45
ruby ruby-on-rails redis resque
Jun 27 2018-12-12T00:
source share
2 answers

yes, this is pretty easy considering you are using a Resque gem :

require 'resque' Resque.info 

will return a hash

eg / =>

 { :pending => 54338, :processed => 12772, :queues => 2, :workers => 0, :working => 0, :failed => 8761, :servers => [ [0] "redis://192.168.1.10:6379/0" ], :environment => "development" } 

So, to get an account of failed work, simply use:

 Resque.info[:failed] 

which would give => 8761 # in my example

To use queues:

 Resque.queues 

returns an array

eg / =>

 [ [0] "superQ", [1] "anotherQ" ] 

Then you can find the number of jobs for each queue:

 Resque.size(queue_name) 

eg / Resque.size("superQ") or Resque.size(Resque.queues[0]) .....

NTN?

+107
Jun 27 2018-12-12T00:
source share

Here is a bash script that will track the total number of jobs in the queue and the number of failed jobs.

 while : do let sum=0 let errors=$(redis-cli llen resque:failed) for s in $(redis-cli keys resque:queue:*) do let sum=$sum+$(redis-cli llen $s) done echo $sum jobs queued, with $errors errors sleep 1 # sleep 1 second, probably want to increase this done 

This is for Resque 1.X, 2.0 may have different key names.

+6
Jun 05 '14 at 3:52
source share



All Articles