mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Remove info for new stats API.
This commit is contained in:
parent
de55c8d542
commit
9ce4fec043
2 changed files with 1 additions and 84 deletions
|
@ -1,31 +1,8 @@
|
|||
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
|
||||
|
||||
def size(*queues)
|
||||
return info[:backlog] if queues.empty?
|
||||
return Sidekiq::Stats.new.enqueued if queues.empty?
|
||||
|
||||
Sidekiq.redis { |conn|
|
||||
conn.multi {
|
||||
|
|
|
@ -18,54 +18,6 @@ class TestStats < MiniTest::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
it 'updates global stats in the success case' do
|
||||
msg = Sidekiq.dump_json({ 'class' => DumbWorker.to_s, 'args' => [""] })
|
||||
boss = MiniTest::Mock.new
|
||||
actor = MiniTest::Mock.new
|
||||
|
||||
@redis.with do |conn|
|
||||
|
||||
set = conn.smembers('workers')
|
||||
assert_equal 0, set.size
|
||||
|
||||
processor = Sidekiq::Processor.new(boss)
|
||||
3.times do
|
||||
actor.expect(:processor_done, nil, [processor])
|
||||
boss.expect(:async, actor, [])
|
||||
end
|
||||
|
||||
assert_equal 0, Sidekiq.info[:failed]
|
||||
assert_equal 0, Sidekiq.info[:processed]
|
||||
|
||||
processor.process(msg, 'xyzzy')
|
||||
processor.process(msg, 'xyzzy')
|
||||
processor.process(msg, 'xyzzy')
|
||||
|
||||
assert_equal 0, Sidekiq.info[:failed]
|
||||
assert_equal 3, Sidekiq.info[:processed]
|
||||
end
|
||||
end
|
||||
|
||||
it 'updates global stats in the error case' do
|
||||
msg = Sidekiq.dump_json({ 'class' => DumbWorker.to_s, 'args' => [nil] })
|
||||
boss = MiniTest::Mock.new
|
||||
|
||||
@redis.with do |conn|
|
||||
assert_equal [], conn.smembers('workers')
|
||||
assert_equal 0, Sidekiq.info[:failed]
|
||||
assert_equal 0, Sidekiq.info[:processed]
|
||||
|
||||
processor = Sidekiq::Processor.new(boss)
|
||||
|
||||
assert_raises RuntimeError do
|
||||
processor.process(msg, 'xyzzy')
|
||||
end
|
||||
|
||||
assert_equal 1, Sidekiq.info[:failed]
|
||||
assert_equal 1, Sidekiq.info[:processed]
|
||||
end
|
||||
end
|
||||
|
||||
describe "info counts" do
|
||||
before do
|
||||
@redis.with do |conn|
|
||||
|
@ -80,18 +32,6 @@ class TestStats < MiniTest::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
describe "queues_with_sizes" do
|
||||
it "returns queue names and corresponding job counts" do
|
||||
assert_equal [["foo", 1], ["baz", 2], ["bar", 3]], Sidekiq.info[:queues_with_sizes]
|
||||
end
|
||||
end
|
||||
|
||||
describe "backlog" do
|
||||
it "returns count of all jobs yet to be processed" do
|
||||
assert_equal 6, Sidekiq.info[:backlog]
|
||||
end
|
||||
end
|
||||
|
||||
describe "size" do
|
||||
it "returns size of queues" do
|
||||
assert_equal 0, Sidekiq.size("foox")
|
||||
|
|
Loading…
Reference in a new issue