Class: Sidekiq::Statistic::Runtime
- Inherits:
-
Object
- Object
- Sidekiq::Statistic::Runtime
- Defined in:
- lib/sidekiq/statistic/statistic/runtime.rb
Instance Method Summary collapse
- #average_runtime ⇒ Object
-
#initialize(redis_statistic, worker, values = nil) ⇒ Runtime
constructor
A new instance of Runtime.
- #last_runtime ⇒ Object
- #max_runtime ⇒ Object
- #min_runtime ⇒ Object
- #total_runtime ⇒ Object
- #values_hash ⇒ Object
Constructor Details
#initialize(redis_statistic, worker, values = nil) ⇒ Runtime
Returns a new instance of Runtime.
4 5 6 7 8 |
# File 'lib/sidekiq/statistic/statistic/runtime.rb', line 4 def initialize(redis_statistic, worker, values = nil) @redis_statistic = redis_statistic @worker = worker @values = values end |
Instance Method Details
#average_runtime ⇒ Object
36 37 38 39 40 41 |
# File 'lib/sidekiq/statistic/statistic/runtime.rb', line 36 def average_runtime averages = values(:average_time) count = averages.count return 0.0 if count == 0 averages.inject(:+) / count end |
#last_runtime ⇒ Object
28 29 30 |
# File 'lib/sidekiq/statistic/statistic/runtime.rb', line 28 def last_runtime @redis_statistic.statistic_for(@worker).last[:last_time] end |
#max_runtime ⇒ Object
20 21 22 |
# File 'lib/sidekiq/statistic/statistic/runtime.rb', line 20 def max_runtime values(:max_time).max || 0.0 end |
#min_runtime ⇒ Object
24 25 26 |
# File 'lib/sidekiq/statistic/statistic/runtime.rb', line 24 def min_runtime values(:min_time).min || 0.0 end |
#total_runtime ⇒ Object
32 33 34 |
# File 'lib/sidekiq/statistic/statistic/runtime.rb', line 32 def total_runtime values(:total_time).inject(:+) || 0.0 end |
#values_hash ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/sidekiq/statistic/statistic/runtime.rb', line 10 def values_hash { last: last_runtime, max: max_runtime.round(3), min: min_runtime.round(3), average: average_runtime.round(3), total: total_runtime.round(3) } end |