mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Allow Sidekiq::Stats#reset to reset individual stats independently
This commit is contained in:
parent
7f589c5139
commit
db0a3336a0
2 changed files with 36 additions and 5 deletions
|
@ -10,10 +10,12 @@ module Sidekiq
|
|||
Sidekiq.redis { |conn| conn.get("stat:failed") }.to_i
|
||||
end
|
||||
|
||||
def reset
|
||||
def reset(*stats)
|
||||
all = %w(failed processed)
|
||||
stats = stats.empty? ? all : all & stats.flatten.compact.map(&:to_s)
|
||||
|
||||
Sidekiq.redis do |conn|
|
||||
conn.set("stat:failed", 0)
|
||||
conn.set("stat:processed", 0)
|
||||
stats.each { |stat| conn.set("stat:#{stat}", 0) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -33,15 +33,44 @@ class TestApi < Sidekiq::Test
|
|||
end
|
||||
|
||||
describe "reset" do
|
||||
it 'can reset stats' do
|
||||
before do
|
||||
Sidekiq.redis do |conn|
|
||||
conn.set('stat:processed', 5)
|
||||
conn.set('stat:failed', 10)
|
||||
Sidekiq::Stats.new.reset
|
||||
end
|
||||
end
|
||||
|
||||
it 'will reset all stats by default' do
|
||||
Sidekiq::Stats.new.reset
|
||||
Sidekiq.redis do |conn|
|
||||
assert_equal '0', conn.get('stat:processed')
|
||||
assert_equal '0', conn.get('stat:failed')
|
||||
end
|
||||
end
|
||||
|
||||
it 'can reset individual stats' do
|
||||
Sidekiq::Stats.new.reset('failed')
|
||||
Sidekiq.redis do |conn|
|
||||
assert_equal '5', conn.get('stat:processed')
|
||||
assert_equal '0', conn.get('stat:failed')
|
||||
end
|
||||
end
|
||||
|
||||
it 'can accept anything that responds to #to_s' do
|
||||
Sidekiq::Stats.new.reset(:failed)
|
||||
Sidekiq.redis do |conn|
|
||||
assert_equal '5', conn.get('stat:processed')
|
||||
assert_equal '0', conn.get('stat:failed')
|
||||
end
|
||||
end
|
||||
|
||||
it 'ignores anything other than "failed" or "processed"' do
|
||||
Sidekiq::Stats.new.reset((1..10).to_a, ['failed'])
|
||||
Sidekiq.redis do |conn|
|
||||
assert_equal '5', conn.get('stat:processed')
|
||||
assert_equal '0', conn.get('stat:failed')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "queues" do
|
||||
|
|
Loading…
Add table
Reference in a new issue