mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
c93a75802c
Useful for other libraries, like hirefire. Implemented specifically to clean up a6de8329. Will close #386 when merged.
35 lines
797 B
Ruby
35 lines
797 B
Ruby
module Sidekiq
|
|
module Stats
|
|
module_function
|
|
|
|
def processed
|
|
(Sidekiq.redis { |conn| conn.get('stat:processed') } || 0).to_i
|
|
end
|
|
|
|
def failed
|
|
(Sidekiq.redis { |conn| conn.get('stat:failed') } || 0).to_i
|
|
end
|
|
|
|
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
|
|
|
|
def backlog
|
|
queues_with_sizes.map {|_, size| size }.inject(0) {|memo, val| memo + val }
|
|
end
|
|
|
|
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
|
|
end
|
|
end
|