1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/lib/sidekiq/stats.rb
2012-12-04 16:52:39 -05:00

26 lines
720 B
Ruby

module Sidekiq
module_function
def info
results = {}
processed, failed, queues = Sidekiq.redis { |conn|
conn.multi do
conn.get('stat:processed')
conn.get('stat:failed')
conn.smembers('queues')
end
}
results[:queues_with_sizes] = Sidekiq.redis do |conn|
queues.inject({}) { |memo, q|
memo[q] = conn.llen("queue:#{q}")
memo
}.sort_by { |_, size| size }
end
results[:processed] = (processed || 0).to_i
results[:failed] = (failed || 0).to_i
results[:backlog] = results[:queues_with_sizes].
map {|_, size| size }.
inject(0) {|memo, val| memo + val }
results
end
end