Module: Judoscale::Resque::LatencyExtension

Defined in:
lib/judoscale/resque/latency_extension.rb

Instance Method Summary collapse

Instance Method Details

#latency(queue) ⇒ Object

Calculate latency for the given queue using the stored timestamp of the oldest item in the queue.



11
12
13
14
15
16
17
18
# File 'lib/judoscale/resque/latency_extension.rb', line 11

def latency(queue)
  if (item = peek(queue))
    timestamp = item["timestamp"]
    timestamp ? Time.now.utc.to_f - timestamp.to_f : 0.0
  else
    0.0
  end
end

#push(queue, item) ⇒ Object

Store the time when jobs are pushed to the queue in order to calculate latency.



5
6
7
8
# File 'lib/judoscale/resque/latency_extension.rb', line 5

def push(queue, item)
  item["timestamp"] = Time.now.utc.to_f
  super
end