2012-09-03 13:37:54 -04:00
|
|
|
module Sidekiq
|
|
|
|
module Stats
|
|
|
|
module_function
|
|
|
|
|
|
|
|
def processed
|
2012-09-03 13:43:08 -04:00
|
|
|
(Sidekiq.redis { |conn| conn.get('stat:processed') } || 0).to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
def failed
|
|
|
|
(Sidekiq.redis { |conn| conn.get('stat:failed') } || 0).to_i
|
2012-09-03 13:37:54 -04:00
|
|
|
end
|
2012-09-03 15:12:51 -04:00
|
|
|
|
|
|
|
def queues_with_sizes
|
|
|
|
Sidekiq.redis { |conn|
|
|
|
|
conn.smembers('queues').inject({}) { |memo, q|
|
|
|
|
memo[q] = conn.llen("queue:#{q}")
|
|
|
|
memo
|
|
|
|
}.sort_by { |_, size| size }
|
|
|
|
}
|
|
|
|
end
|
2012-09-03 15:19:01 -04:00
|
|
|
|
|
|
|
def backlog
|
|
|
|
queues_with_sizes.map {|_, size| size }.inject(0) {|memo, val| memo + val }
|
|
|
|
end
|
2012-09-03 15:36:38 -04:00
|
|
|
|
|
|
|
def size(*queues)
|
|
|
|
return backlog if queues.empty?
|
|
|
|
queues.
|
|
|
|
map(&:to_s).
|
|
|
|
inject(0) { |memo, queue|
|
|
|
|
memo += Sidekiq.redis { |conn| conn.llen("queue:#{queue}") }
|
|
|
|
}
|
|
|
|
end
|
2012-09-03 13:37:54 -04:00
|
|
|
end
|
|
|
|
end
|