sidekiq-reset_statistics 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5619fdb46cfb1820c15c0b524ba349c883514324
4
- data.tar.gz: eaf5bab3bcf0e681183e0a713972938ee5d73f47
3
+ metadata.gz: 7eb64a314a3efea7e626b77b0a7e1efba7bf69ea
4
+ data.tar.gz: 06f12568a63d1abcf34cf53fa157808b95c7b0a1
5
5
  SHA512:
6
- metadata.gz: f3cd75d7f2d6e71d48a8a563597c4b5bbecaca8e7e8e1c23535e4f2d7ad471da9707a48273590e75b7b86555e5d53de49dbdf2c85d4a92a2a50bad856595a725
7
- data.tar.gz: fc5e09b8f32f1cda49e224d2adef152b67cb4295095dad2959bf8050235a2aaa1cc2e2b6b7593c3331f7d80ddc9f22f75f4920b3622c8402ed9c52d80448b21d
6
+ metadata.gz: cab24524b9f8388d64b7555f956e7b21cf3ca59daf8b362b72b6a3b6f2f434c6414a3285d150245235992eced901db9bfe78d45542b03442f0445a4e08b64b98
7
+ data.tar.gz: 2deefca85797f5b223626074aaa0547af9d0f2b5bfec254118775d09d34cd9e15ee77e6fb61e643e54733800493231b7e0bdccde12b4a3cfa955c992fc1a683d
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.0 (2014-01-12)
4
+
5
+ * Use updated `Sidekiq::Stats#reset` to reset individual stats independently. Thanks @bwthomas
6
+
3
7
  ## 1.0.0 (2013-09-12)
4
8
 
5
9
  * Initial release
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 David Czarnecki
1
+ Copyright (c) 2013-2014 David Czarnecki
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -22,4 +22,4 @@ gem 'sidekiq-reset_statistics'
22
22
 
23
23
  ## Copyright
24
24
 
25
- Copyright (c) 2013 David Czarnecki. See LICENSE.txt for further details.
25
+ Copyright (c) 2013-2014 David Czarnecki. See LICENSE.txt for further details.
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module ResetStatistics
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
@@ -10,10 +10,21 @@ module Sidekiq
10
10
  end
11
11
 
12
12
  app.post "/reset-statistics" do
13
- Sidekiq::Stats.new.reset
13
+ stats = Sidekiq::Stats.new
14
+ resets = params.values.grep(/Reset (?!All)/)
15
+
16
+ if resets.empty?
17
+ stats.reset
18
+ elsif stats.method(:reset).arity != -1
19
+ raise StandardError, "Version mismatch. Please upgrade Sidekiq."
20
+ else
21
+ counts = resets.map {|r| r.split.last.downcase }
22
+ stats.reset(*counts)
23
+ end
24
+
14
25
  redirect root_path
15
26
  end
16
27
  end
17
28
  end
18
29
  end
19
- end
30
+ end
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Sidekiq::ResetStatistics::VERSION' do
4
4
  it 'should be the correct version' do
5
- Sidekiq::ResetStatistics::VERSION.should == '1.0.0'
5
+ Sidekiq::ResetStatistics::VERSION.should == '1.1.0'
6
6
  end
7
7
  end
@@ -3,27 +3,74 @@ require 'spec_helper'
3
3
  describe Sidekiq::ResetStatistics::Web do
4
4
  include Rack::Test::Methods
5
5
 
6
- before do
7
- Sidekiq.redis { |conn| conn.flushdb }
8
- end
6
+ STATS = %w(processed failed).freeze unless defined?(STATS)
9
7
 
10
8
  def app
11
9
  @app ||= Sidekiq::Web
12
10
  end
13
11
 
12
+ before do
13
+ Sidekiq.redis do |conn|
14
+ conn.flushdb
15
+ STATS.each { |stat| conn.set("stat:#{stat}", 5) }
16
+ end
17
+ end
18
+
14
19
  it 'should display the index page' do
15
20
  get '/reset-statistics'
16
21
  last_response.status.should == 200
17
22
  end
18
23
 
19
- it 'should reset statistics in Sidekiq' do
24
+ it 'should reset all statistics in Sidekiq by default' do
25
+ post '/reset-statistics'
26
+ last_response.status.should == 302
27
+
28
+ Sidekiq.redis do |conn|
29
+ STATS.each { |stat| conn.get("stat:#{stat}").should == '0' }
30
+ end
31
+ end
32
+
33
+ it 'should reset all statistics in Sidekiq when asked' do
34
+ post '/reset-statistics', :reset_all => 'Reset All'
35
+ last_response.status.should == 302
36
+
20
37
  Sidekiq.redis do |conn|
21
- conn.set('stat:processed', 5)
22
- conn.set('stat:failed', 10)
23
- post '/reset-statistics'
38
+ STATS.each { |stat| conn.get("stat:#{stat}").should == '0' }
39
+ end
40
+ end
41
+
42
+ STATS.each do |stat|
43
+ it "should reset #{stat} when asked" do
44
+ post '/reset-statistics', "reset_#{stat}" => "Reset #{stat.capitalize}"
24
45
  last_response.status.should == 302
25
- conn.get('stat:processed').should == '0'
26
- conn.get('stat:failed').should == '0'
46
+
47
+ Sidekiq.redis do |conn|
48
+ conn.get("stat:#{stat}").should == '0'
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'version mismatch' do
54
+ before do
55
+ method_class = String.method(:new).class
56
+ instance_method_class = String.instance_method(:size).class
57
+ method_class.any_instance.stub(:arity => 0)
58
+ instance_method_class.any_instance.stub(:arity => 0)
59
+ end
60
+
61
+ it 'should not raise an error when requested action is compatible with sidekiq' do
62
+ post '/reset-statistics', :reset_all => 'Reset All'
63
+ last_response.status.should == 302
64
+
65
+ Sidekiq.redis do |conn|
66
+ STATS.each { |stat| conn.get("stat:#{stat}").should == '0' }
67
+ end
68
+ end
69
+
70
+ it 'should raise an error when requested action is incompatible with sidekiq' do
71
+ post '/reset-statistics', :reset_foo => 'Reset Foo'
72
+ last_response.status.should == 500
73
+ last_response.errors.should include('Version mismatch. Please upgrade Sidekiq')
27
74
  end
28
75
  end
29
- end
76
+ end
@@ -1,3 +1,7 @@
1
1
  <form action="<%= root_path %>reset-statistics" method="post">
2
- <input class="btn btn-danger pull-left" type="submit" name="reset_statistics" value="Reset Sidekiq Statistics" data-confirm="<%= t('AreYouSure') %>"/>
3
- </form>
2
+ <% if Sidekiq::Stats.instance_method(:reset).arity == -1 %>
3
+ <input class="btn btn-danger pull-left" type="submit" name="reset_processed" value="Reset Processed" data-confirm="<%= t('AreYouSure') %>"/>
4
+ <input class="btn btn-danger pull-left" type="submit" name="reset_failed" value="Reset Failed" data-confirm="<%= t('AreYouSure') %>"/>
5
+ <% end %>
6
+ <input class="btn btn-danger pull-left" type="submit" name="reset_all" value="Reset All" data-confirm="<%= t('AreYouSure') %>"/>
7
+ </form>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-reset_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Czarnecki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-12 00:00:00.000000000 Z
11
+ date: 2014-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  requirements: []
124
124
  rubyforge_project: sidekiq-reset_statistics
125
- rubygems_version: 2.0.3
125
+ rubygems_version: 2.0.5
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: Adds a tab to your Sidekiq dashboard to allow you to reset Sidekiq statistics