Skip to content

Commit

Permalink
Merge pull request #18 from krasnoukhov/clear-sidekiq-stat-on-remove
Browse files Browse the repository at this point in the history
Clear sidekiq stat on remove
  • Loading branch information
mhfs committed Dec 30, 2012
2 parents 99f3791 + 26f6994 commit 90937df
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/sidekiq/failures/views/failures.slim
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ header.row


div.row div.row
.span5 .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" 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 .span4
== slim :_paging, :locals => { :url => "#{root_path}failures#@name" } == slim :_paging, :locals => { :url => "#{root_path}failures#@name" }
- else - else
Expand Down
7 changes: 6 additions & 1 deletion lib/sidekiq/failures/web_extension.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ def find_template(view, *a, &b)
end end


app.post "/failures/remove" do 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" redirect "#{root_path}failures"
end end
Expand Down
37 changes: 35 additions & 2 deletions test/web_extension_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def app
last_response.body.must_match /Clear All/ last_response.body.must_match /Clear All/
end 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/ last_response.body.must_match /HardWorker/


post '/failures/remove' post '/failures/remove'
Expand All @@ -61,6 +65,30 @@ def app
get '/failures' get '/failures'
last_response.status.must_equal 200 last_response.status.must_equal 200
last_response.body.must_match /No failed jobs found/ 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
end end


Expand All @@ -75,7 +103,12 @@ def create_sample_failure
:queue => 'default' :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 end
end end

0 comments on commit 90937df

Please sign in to comment.