2012-09-03 13:37:54 -04:00
|
|
|
module Sidekiq
|
2012-09-04 01:38:51 -04:00
|
|
|
module_function
|
2012-09-03 13:37:54 -04:00
|
|
|
|
2012-09-04 01:38:51 -04:00
|
|
|
def info
|
|
|
|
results = {}
|
2012-09-04 12:59:02 -04:00
|
|
|
processed, failed, queues = Sidekiq.redis { |conn|
|
|
|
|
conn.multi do
|
|
|
|
conn.get('stat:processed')
|
|
|
|
conn.get('stat:failed')
|
|
|
|
conn.smembers('queues')
|
2012-09-04 01:38:51 -04:00
|
|
|
end
|
|
|
|
}
|
2012-09-04 01:41:32 -04:00
|
|
|
results[:queues_with_sizes] = Sidekiq.redis do |conn|
|
2012-09-04 12:59:02 -04:00
|
|
|
queues.inject({}) { |memo, q|
|
2012-09-04 01:38:51 -04:00
|
|
|
memo[q] = conn.llen("queue:#{q}")
|
|
|
|
memo
|
|
|
|
}.sort_by { |_, size| size }
|
2012-09-03 13:43:08 -04:00
|
|
|
end
|
2012-09-04 12:59:02 -04:00
|
|
|
results[:processed] = (processed || 0).to_i
|
|
|
|
results[:failed] = (failed || 0).to_i
|
2012-09-04 01:41:32 -04:00
|
|
|
results[:backlog] = results[:queues_with_sizes].
|
2012-09-04 01:38:51 -04:00
|
|
|
map {|_, size| size }.
|
|
|
|
inject(0) {|memo, val| memo + val }
|
|
|
|
results
|
|
|
|
end
|
2012-12-04 12:13:47 -05:00
|
|
|
|
|
|
|
def size(*queues)
|
|
|
|
return info[:backlog] if queues.empty?
|
|
|
|
|
|
|
|
Sidekiq.redis { |conn|
|
|
|
|
conn.multi {
|
|
|
|
queues.map { |q| conn.llen("queue:#{q}") }
|
|
|
|
}
|
|
|
|
}.inject(0) { |memo, count| memo += count }
|
|
|
|
end
|
2012-09-03 13:37:54 -04:00
|
|
|
end
|