sidekiq-benchmark 0.5.0 → 0.5.1

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: 2b2583957b88fb1d556a08a53abe16bc823914ec
4
- data.tar.gz: d084d3be5a35c882326c9d3f8df418c0a9c2bca6
3
+ metadata.gz: 1f1b169c529b283e1e168119469196b3e597cb52
4
+ data.tar.gz: 4baa60ef47937686077547331e5a993b0d0642ef
5
5
  SHA512:
6
- metadata.gz: b0662eec56c195a7077a263c10926e6b7484fde4fb54b7f0d45db8b70e61e74847bf2f35b9c1c9d1a60671362f6ee6970306358af0381e79073013facc47db05
7
- data.tar.gz: 1e7042f4b933e3776cbeaea2cf682a86a69ffc1416f4da4784110036439e0ad9d85f98dc24d5b043e0f1eec7c3f67a5587a20dae443d2e019b576fbb46000ca0
6
+ metadata.gz: 80d23555c511e4d08ab7a284ddf1069635ed153020798f5655ab0ec85f84c3a2a480beebb8f7c37ca4a6eed376ca3a3a0639d7eb74ce85d71ad8eed91da097a6
7
+ data.tar.gz: 0f577d9211c64b8e63f725b09312eff473eea8e3c4048e9d70877e9922d8f4746cb3e1db385a7999ef4e3e775b79d0cc8f39788fc978dd5d00cb673a6787580a
data/README.md CHANGED
@@ -19,7 +19,7 @@ And then execute:
19
19
 
20
20
  ## Requirements
21
21
 
22
- Redis 2.6.0 or newer required
22
+ From version 0.5.0 works with Sidekiq 4.2 or newer
23
23
 
24
24
  ## Usage
25
25
 
@@ -92,6 +92,3 @@ require 'sidekiq-benchmark/testing'
92
92
  3. Commit your changes (`git commit -am 'Add some feature'`)
93
93
  4. Push to the branch (`git push origin my-new-feature`)
94
94
  5. Create new Pull Request
95
-
96
-
97
- [![endorse](https://api.coderwall.com/kosmatov/endorsecount.png)](https://coderwall.com/kosmatov)
@@ -8,6 +8,7 @@ module Sidekiq
8
8
  module Benchmark
9
9
  REDIS_NAMESPACE = :benchmark
10
10
  TYPES_KEY = "#{REDIS_NAMESPACE}:types".freeze
11
+ STAT_KEYS = %i[stats total]
11
12
  REDIS_KEYS_TTL = 3600 * 24 * 30
12
13
 
13
14
  autoload :Worker, 'sidekiq-benchmark/worker'
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Benchmark
3
- VERSION = "0.5.0"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  end
@@ -23,11 +23,11 @@ module Sidekiq
23
23
  @charts = {}
24
24
 
25
25
  Sidekiq.redis do |conn|
26
- @types = conn.smembers Sidekiq::Benchmark::TYPES_KEY
26
+ @types = conn.smembers TYPES_KEY
27
27
  @types.each do |type|
28
- @charts[type] = { total: [], stats: [] }
28
+ @charts[type] = STAT_KEYS.reduce({}) { |a, e| a[e] = []; a }
29
29
 
30
- total_key = "#{Sidekiq::Benchmark::REDIS_NAMESPACE}:#{type}:total"
30
+ total_key = "#{REDIS_NAMESPACE}:#{type}:total"
31
31
  total_keys = conn.hkeys(total_key) - %w(start_time job_time finish_time)
32
32
 
33
33
  total_time = conn.hget total_key, :job_time
@@ -37,7 +37,7 @@ module Sidekiq
37
37
  @charts[type][:total] << [key, value.to_f.round(2)]
38
38
  end
39
39
 
40
- stats = conn.hgetall "#{Sidekiq::Benchmark::REDIS_NAMESPACE}:#{type}:stats"
40
+ stats = conn.hgetall "#{REDIS_NAMESPACE}:#{type}:stats"
41
41
  stats.each do |key, value|
42
42
  @charts[type][:stats] << [key.to_f, value.to_i]
43
43
  end
@@ -52,7 +52,20 @@ module Sidekiq
52
52
 
53
53
  app.post "/benchmarks/remove" do
54
54
  Sidekiq.redis do |conn|
55
- keys = conn.keys "benchmark:*"
55
+ keys = STAT_KEYS.map { |key| "#{REDIS_NAMESPACE}:#{params[:type]}:#{key}" }
56
+ conn.srem TYPES_KEY, params[:type]
57
+ conn.del keys
58
+ end
59
+
60
+ redirect "#{root_path}benchmarks"
61
+ end
62
+ app.post "/benchmarks/remove_all" do
63
+ Sidekiq.redis do |conn|
64
+ types = conn.smembers TYPES_KEY
65
+ keys = STAT_KEYS.map do |key|
66
+ types.map { |type| "#{REDIS_NAMESPACE}:#{type}:#{key}" }
67
+ end.flatten
68
+ keys << TYPES_KEY
56
69
  conn.del keys
57
70
  end
58
71
 
@@ -68,8 +68,8 @@ module Sidekiq
68
68
 
69
69
  def set_redis_key(key)
70
70
  Sidekiq.redis do |conn|
71
- conn.sadd Sidekiq::Benchmark::TYPES_KEY, key
72
- conn.expire Sidekiq::Benchmark::TYPES_KEY, REDIS_KEYS_TTL
71
+ conn.sadd TYPES_KEY, key
72
+ conn.expire TYPES_KEY, REDIS_KEYS_TTL
73
73
  end
74
74
  end
75
75
 
@@ -14,33 +14,38 @@ module Sidekiq
14
14
  Test.flush_db
15
15
  end
16
16
 
17
- it "should display index without stats" do
17
+ it "display index without stats" do
18
18
  get '/benchmarks'
19
19
  last_response.status.must_equal 200
20
20
  end
21
21
 
22
- it "should display index with stats" do
22
+ it "display index with stats" do
23
23
  WorkerMock.new
24
24
 
25
25
  get '/benchmarks'
26
26
  last_response.status.must_equal 200
27
27
  end
28
28
 
29
- it "should remove benchmarks data" do
29
+ it "remove all benchmarks data" do
30
30
  WorkerMock.new
31
31
 
32
- Sidekiq.redis do |conn|
33
- keys = conn.keys "benchmark:*"
34
- keys.wont_be_empty
35
- end
32
+ Sidekiq.redis { |conn| conn.keys("benchmark:*").wont_be_empty }
36
33
 
37
- post '/benchmarks/remove'
34
+ post '/benchmarks/remove_all'
38
35
  last_response.status.must_equal 302
39
36
 
40
- Sidekiq.redis do |conn|
41
- keys = conn.keys "benchmark:*"
42
- keys.must_be_empty
43
- end
37
+ Sidekiq.redis { |conn| conn.keys("benchmark:*").must_be_empty }
38
+ end
39
+
40
+ it "remove benchmark data" do
41
+ WorkerMock.new
42
+
43
+ Sidekiq.redis { |conn| conn.keys("benchmark:sidekiq_benchmark_test_workermock:*").wont_be_empty }
44
+
45
+ post '/benchmarks/remove', type: :sidekiq_benchmark_test_workermock
46
+ last_response.status.must_equal 302
47
+
48
+ Sidekiq.redis { |conn| conn.keys("benchmark:sidekiq_benchmark_test_workermock:*").must_be_empty }
44
49
  end
45
50
  end
46
51
  end
@@ -5,11 +5,33 @@
5
5
  <div class="col-md-6">
6
6
  <h3>Benchmarks</h3>
7
7
  </div>
8
+
9
+ <div class="col-md-6">
10
+ <form method="POST" class="warning-messages" action="<%= root_path %>benchmarks/remove_all">
11
+ <%= csrf_tag %>
12
+ <div class="pull-right">
13
+ <button class="btn btn-danger" type="submit" name="clear" value="1" data-confirm="<%= t('AreYouSure') %>"><%= t('DeleteAll') %></button>
14
+ </div>
15
+ </form>
16
+ </div>
8
17
  </header>
9
18
 
10
- <section>
11
19
  <% @types.each do |type| %>
12
- <h4><%= type %></h4>
20
+ <section>
21
+ <div class="row">
22
+ <div class="col-md-6">
23
+ <h4><%= type %></h4>
24
+ </div>
25
+ <div class="col-md-6">
26
+ <form method="POST" class="warning-messages" action="<%= root_path %>benchmarks/remove">
27
+ <%= csrf_tag %>
28
+ <div class="pull-right">
29
+ <input type="hidden" name="type" value="<%= type %>"/>
30
+ <button class="btn btn-danger" type="submit" name="clear" value="1" data-confirm="<%= t('AreYouSure') %>"><%= t('Delete') %></button>
31
+ </div>
32
+ </form>
33
+ </div>
34
+ </div>
13
35
  <figure class="row">
14
36
  <div class="col-md-7">
15
37
  <h5>Amount of tasks by execution time</h5>
@@ -20,5 +42,5 @@
20
42
  <%= pie_chart @charts[type][:total] %>
21
43
  </div>
22
44
  </figure>
23
- <% end %>
24
45
  </section>
46
+ <% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-benchmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Kosmatov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-11 00:00:00.000000000 Z
11
+ date: 2016-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chartkick