Class: Sidekiq::Statistic::Runtime

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/statistic/statistic/runtime.rb

Instance Method Summary collapse

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_runtimeObject



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_runtimeObject



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_runtimeObject



20
21
22
# File 'lib/sidekiq/statistic/statistic/runtime.rb', line 20

def max_runtime
  values(:max_time).max || 0.0
end

#min_runtimeObject



24
25
26
# File 'lib/sidekiq/statistic/statistic/runtime.rb', line 24

def min_runtime
  values(:min_time).min || 0.0
end

#total_runtimeObject



32
33
34
# File 'lib/sidekiq/statistic/statistic/runtime.rb', line 32

def total_runtime
  values(:total_time).inject(:+) || 0.0
end

#values_hashObject



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