Method: Sidekiq::Queue#latency

Defined in:
lib/sidekiq/api.rb

#latencyObject

Calculates this queue’s latency, the difference in seconds since the oldest job in the queue was enqueued.

Returns:

  • Float



232
233
234
235
236
237
238
239
240
241
# File 'lib/sidekiq/api.rb', line 232

def latency
  entry = Sidekiq.redis { |conn|
    conn.lrange(@rname, -1, -1)
  }.first
  return 0 unless entry
  job = Sidekiq.load_json(entry)
  now = Time.now.to_f
  thence = job["enqueued_at"] || now
  now - thence
end