Method: Sidekiq::Queue#latency
- Defined in:
- lib/sidekiq/api.rb
#latency ⇒ Float
Calculates this queue’s latency, the difference in seconds since the oldest job in the queue was enqueued.
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/sidekiq/api.rb', line 273 def latency entry = Sidekiq.redis { |conn| conn.lindex(@rname, -1) } return 0.0 unless entry job = Sidekiq.load_json(entry) enqueued_at = job["enqueued_at"] if enqueued_at if enqueued_at.is_a?(Float) # old format now = Time.now.to_f now - enqueued_at else now = ::Process.clock_gettime(::Process::CLOCK_REALTIME, :millisecond) (now - enqueued_at) / 1000.0 end else 0.0 end end |