peek-sidekiq 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 1.0.3
2
+
3
+ - Fixed incorrect placement of the instrumented methods in the class.
4
+
5
+ # 1.0.2
6
+
7
+ - Now rendering duration & calls generated by the page, not global, as per issue #1.
8
+
9
+ Thanks to @mperham for advice on how to do that!
10
+
1
11
  # 1.0.1
2
12
 
3
13
  - Renamed glimpse to peek.
data/README.md CHANGED
@@ -4,9 +4,8 @@ Provide a peek into the Sidekiq calls made within your Rails application.
4
4
 
5
5
  Things this peek view provides:
6
6
 
7
- - Processed jobs
8
- - Failed jobs
9
- - Enqueued jobs
7
+ - Duration spent in Sidekiq calls
8
+ - Number of calls this page created
10
9
 
11
10
  ## Installation
12
11
 
@@ -50,10 +49,10 @@ Build the gem:
50
49
 
51
50
  Push to rubygems.org:
52
51
 
53
- gem push peek-sidekiq-1.0.1.gem
52
+ gem push peek-sidekiq-1.0.3.gem
54
53
 
55
54
  ## Testing the gem locally
56
55
 
57
- gem install peek-sidekiq-1.0.1.gem
56
+ gem install peek-sidekiq-1.0.3.gem
58
57
 
59
58
 
@@ -1,5 +1,4 @@
1
1
  <strong>
2
- P: <span data-defer-to="<%= view.defer_key %>-processed"></span>
3
- F: <span data-defer-to="<%= view.defer_key %>-failed"></span>
4
- E: <span data-defer-to="<%= view.defer_key %>-enqueued"></span>
2
+ <span data-defer-to="<%= view.defer_key %>-duration"></span>
3
+ <span data-defer-to="<%= view.defer_key %>-calls"></span>
5
4
  </strong> sidekiq
@@ -1,5 +1,5 @@
1
1
  module Peek
2
2
  module Sidekiq
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.3'
4
4
  end
5
5
  end
@@ -1,35 +1,67 @@
1
1
  require 'sidekiq'
2
+ require 'atomic'
3
+
4
+ class Sidekiq::Client
5
+ class << self
6
+ attr_accessor :query_time, :query_count
7
+
8
+ def push_with_timing(*args)
9
+ start = Time.now
10
+ push_without_timing(*args)
11
+ ensure
12
+ duration = (Time.now - start)
13
+ @query_time.update { |value| value + duration }
14
+ @query_count.update { |value| value + 1 }
15
+ end
16
+ alias_method_chain :push, :timing
17
+
18
+ def push_bulk_with_timing(*args)
19
+ start = Time.now
20
+ push_bulk_without_timing(*args)
21
+ ensure
22
+ duration = (Time.now - start)
23
+ @query_time.update { |value| value + duration }
24
+ @query_count.update { |value| value + 1 }
25
+ end
26
+ end
27
+
28
+ self.query_count = Atomic.new(0)
29
+ self.query_time = Atomic.new(0)
30
+ end
2
31
 
3
32
  module Peek
4
33
  module Views
5
34
  class Sidekiq < View
6
- def processed
7
- stats.processed
35
+ def duration
36
+ ::Sidekiq::Client.query_time.value
8
37
  end
9
38
 
10
- def failed
11
- stats.failed
39
+ def formatted_duration
40
+ ms = duration * 1000
41
+ if ms >= 1000
42
+ "%.2fms" % ms
43
+ else
44
+ "%.0fms" % ms
45
+ end
12
46
  end
13
47
 
14
- def enqueued
15
- stats.enqueued
48
+ def calls
49
+ ::Sidekiq::Client.query_count.value
16
50
  end
17
51
 
18
52
  def results
19
- {
20
- processed: processed,
21
- failed: failed,
22
- enqueued: enqueued
23
- }
53
+ {:duration => formatted_duration, :calls => calls}
24
54
  end
25
55
 
26
56
  private
27
- def stats
28
- @stats ||= ::Sidekiq::Stats.new
29
- Rails.logger.debug @stats.processed
30
- @stats
31
- end
32
57
 
58
+ def setup_subscribers
59
+ # Reset each counter when a new request starts
60
+ before_request do
61
+ ::Sidekiq::Client.query_time.value = 0
62
+ ::Sidekiq::Client.query_count.value = 0
63
+ end
64
+ end
33
65
  end
34
66
  end
35
67
  end
data/peek-sidekiq.gemspec CHANGED
@@ -19,4 +19,6 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency 'peek'
21
21
  gem.add_dependency 'sidekiq'
22
+ gem.add_dependency 'atomic', '>= 1.0.0'
23
+
22
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peek-sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: atomic
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
46
62
  description: Provide a peek into the Sidekiq calls made within your Rails application.
47
63
  email:
48
64
  - david.parry@suranyami.com