Class: WorkerRoulette::QueueLatency::Tradesman

Inherits:
Object
  • Object
show all
Includes:
QueueMetricTracker
Defined in:
lib/worker_roulette/queue_latency.rb

Instance Method Summary collapse

Methods included from QueueMetricTracker

#calculate_stats, #calculator, #channel, #config, configure, #enabled?, #granularity, included, ip_address, #message, track_all, #tracker_send

Instance Method Details

#process(work_order, channel) ⇒ Object



16
17
18
19
# File 'lib/worker_roulette/queue_latency.rb', line 16

def process(work_order, channel)
  send_latency(work_order["headers"]["queued_at"], channel)
  work_order
end

#send_latency(queued_at, channel) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/worker_roulette/queue_latency.rb', line 21

def send_latency(queued_at, channel)
  return unless queued_at

  latency_ns = (Time.now.to_f * GRANULARITY).to_i - queued_at

  if value = calculate_stats(:queue_latency, latency_ns / 1000.0)
    tracker_send(message("queue_latency(ms)", channel, value))
  end
end