Class: Chillout::Middleware::SidekiqJobMeasurement

Inherits:
Object
  • Object
show all
Defined in:
lib/chillout/middleware/sidekiq.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, queue, started, finished, success) ⇒ SidekiqJobMeasurement

Returns a new instance of SidekiqJobMeasurement.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/chillout/middleware/sidekiq.rb', line 8

def initialize(job, queue, started, finished, success)
  @class     = job["class"].to_s
  @retriable = job["retry"].to_s
  @queue     = queue
  @started   = started.utc
  @finished  = finished.utc
  enqueued_at = job["enqueued_at"] || @finished.to_f
  @delay = 1000.0 * (@finished.to_f - enqueued_at)
  @duration = 1000.0 * (@finished.to_f - @started.to_f)
  @success = success.to_s
end

Instance Attribute Details

#delayObject (readonly)

Returns the value of attribute delay.



5
6
7
# File 'lib/chillout/middleware/sidekiq.rb', line 5

def delay
  @delay
end

#durationObject (readonly)

Returns the value of attribute duration.



5
6
7
# File 'lib/chillout/middleware/sidekiq.rb', line 5

def duration
  @duration
end

#finishedObject (readonly)

Returns the value of attribute finished.



5
6
7
# File 'lib/chillout/middleware/sidekiq.rb', line 5

def finished
  @finished
end

#queueObject (readonly)

Returns the value of attribute queue.



5
6
7
# File 'lib/chillout/middleware/sidekiq.rb', line 5

def queue
  @queue
end

#retriableObject (readonly)

Returns the value of attribute retriable.



5
6
7
# File 'lib/chillout/middleware/sidekiq.rb', line 5

def retriable
  @retriable
end

#startedObject (readonly)

Returns the value of attribute started.



5
6
7
# File 'lib/chillout/middleware/sidekiq.rb', line 5

def started
  @started
end

#successObject (readonly)

Returns the value of attribute success.



5
6
7
# File 'lib/chillout/middleware/sidekiq.rb', line 5

def success
  @success
end

Instance Method Details

#as_measurementsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/chillout/middleware/sidekiq.rb', line 24

def as_measurements()
  [{
    series: "sidekiq_jobs",
    tags: {
      class: @class,
      retriable: @retriable,
      queue: @queue,
      success: @success.to_s,
    },
    timestamp: @finished.iso8601,
    values: {
      finished: 1,
      duration: @duration.to_f,
      delay: @delay.to_f
    },
  }]
end

#job_classObject



20
21
22
# File 'lib/chillout/middleware/sidekiq.rb', line 20

def job_class
  @class
end