Programmatically get the number of jobs in a Resque queue

yes it’s quite easy, given you’re using the Resque gem:

require 'resque'

Resque.info 

will return a hash

e.g/ =>

{
      :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 the failed job count, simply use:

Resque.info[:failed]

which would give
=> 8761 #in my example

To get the queues use:

Resque.queues

this returns a array

e.g./ =>

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

You may then find the number of jobs per queue:

Resque.size(queue_name)

e.g/ Resque.size("superQ") or Resque.size(Resque.queues[0]) …..

Leave a Comment

techhipbettruvabetnorabahisbahis forumu