Permalink
Browse files

Merge pull request #18 from krasnoukhov/clear-sidekiq-stat-on-remove

Clear sidekiq stat on remove
  • Loading branch information...
2 parents 99f3791 + 26f6994 commit 90937dfea1750d4d9b87338acc015b21cdf1c865 @mhfs committed Dec 30, 2012
Showing with 45 additions and 4 deletions.
  1. +4 −1 lib/sidekiq/failures/views/failures.slim
  2. +6 −1 lib/sidekiq/failures/web_extension.rb
  3. +35 −2 test/web_extension_test.rb
@@ -28,8 +28,11 @@ header.row
div.row
.span5
- form.form-horizontal action="#{root_path}failures/remove" method="post" style="margin: 20px 0"
+ form.form-inline action="#{root_path}failures/remove" method="post" style="margin: 20px 0"
input.btn.btn-danger.btn-small type="submit" name="delete" value="Clear All"
+ label class="checkbox"
+ input type="checkbox" name="counter" value="true"
+ = "clear counter"
.span4
== slim :_paging, :locals => { :url => "#{root_path}failures#@name" }
- else
@@ -20,7 +20,12 @@ def find_template(view, *a, &b)
end
app.post "/failures/remove" do
- Sidekiq.redis {|c| c.del(:failed) }
+ Sidekiq.redis {|c|
+ c.multi do
+ c.del("failed")
+ c.del("stat:failed") if params["counter"]
+ end
+ }
redirect "#{root_path}failures"
end
View
@@ -51,7 +51,11 @@ def app
last_response.body.must_match /Clear All/
end
- it 'can remove all failures' do
+ it 'can remove all failures without clearing counter' do
+ Sidekiq.redis do |c|
+ assert_equal c.get("stat:failed"), "1"
+ end
+
last_response.body.must_match /HardWorker/
post '/failures/remove'
@@ -61,6 +65,30 @@ def app
get '/failures'
last_response.status.must_equal 200
last_response.body.must_match /No failed jobs found/
+
+ Sidekiq.redis do |c|
+ assert_equal c.get("stat:failed"), "1"
+ end
+ end
+
+ it 'can remove all failures and clear counter' do
+ Sidekiq.redis do |c|
+ assert_equal c.get("stat:failed"), "1"
+ end
+
+ last_response.body.must_match /HardWorker/
+
+ post '/failures/remove', counter: "true"
+ last_response.status.must_equal 302
+ last_response.location.must_match /failures$/
+
+ get '/failures'
+ last_response.status.must_equal 200
+ last_response.body.must_match /No failed jobs found/
+
+ Sidekiq.redis do |c|
+ assert_nil c.get("stat:failed")
+ end
end
end
@@ -75,7 +103,12 @@ def create_sample_failure
:queue => 'default'
}
- Sidekiq.redis { |conn| conn.rpush(:failed, Sidekiq.dump_json(data)) }
+ Sidekiq.redis do |c|
+ c.multi do
+ c.rpush("failed", Sidekiq.dump_json(data))
+ c.incrby("stat:failed", 1)
+ end
+ end
end
end
end

0 comments on commit 90937df

Please sign in to comment.