class Sidekiq::Statistic::Runtime
Public Class Methods
new(redis_statistic, worker, values = nil)
click to toggle source
# File lib/sidekiq/statistic/statistic/runtime.rb, line 6 def initialize(redis_statistic, worker, values = nil) @redis_statistic = redis_statistic @worker = worker @values = values end
Public Instance Methods
average_runtime()
click to toggle source
# File lib/sidekiq/statistic/statistic/runtime.rb, line 38 def average_runtime averages = values(:average_time).map(&:to_f) count = averages.count return 0.0 if count == 0 averages.inject(:+) / count end
last_runtime()
click to toggle source
# File lib/sidekiq/statistic/statistic/runtime.rb, line 30 def last_runtime @redis_statistic.statistic_for(@worker).last[:last_time] end
max_runtime()
click to toggle source
# File lib/sidekiq/statistic/statistic/runtime.rb, line 22 def max_runtime values(:max_time).map(&:to_f).max || 0.0 end
min_runtime()
click to toggle source
# File lib/sidekiq/statistic/statistic/runtime.rb, line 26 def min_runtime values(:min_time).map(&:to_f).min || 0.0 end
total_runtime()
click to toggle source
# File lib/sidekiq/statistic/statistic/runtime.rb, line 34 def total_runtime values(:total_time).map(&:to_f).inject(:+) || 0.0 end
values_hash()
click to toggle source
# File lib/sidekiq/statistic/statistic/runtime.rb, line 12 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
Private Instance Methods
values(key)
click to toggle source
# File lib/sidekiq/statistic/statistic/runtime.rb, line 47 def values(key) @values ||= @redis_statistic.statistic_for(@worker) @values = @values.is_a?(Array) ? @values : [@values] @values.map{ |s| s[key] }.compact end