Sha256: 2b2fed4678fde1f319ceb1a587f5af62076b55b171eea69877939cc08d60a667
Contents?: true
Size: 1.09 KB
Versions: 2
Compression:
Stored size: 1.09 KB
Contents
module Sidekiq module Statistic class Runtime def initialize(redis_statistic, worker, values = nil) @redis_statistic = redis_statistic @worker = worker @values = values end 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 def max_runtime values(:max_time).max || 0.0 end def min_runtime values(:min_time).min || 0.0 end def last_runtime @redis_statistic.statistic_for(@worker).last[:last_time] end def total_runtime values(:total_time).inject(:+) || 0.0 end def average_runtime averages = values(:average_time) count = averages.count return 0.0 if count == 0 averages.inject(:+) / count end private def values(key) @values ||= @redis_statistic.statistic_for(@worker) @values.map{ |s| s[key] }.compact end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sidekiq-statistic-1.1.0 | lib/sidekiq/statistic/statistic/runtime.rb |
sidekiq-statistic-1.0.0 | lib/sidekiq/statistic/statistic/runtime.rb |