mperham/sidekiq — pull request #944 by mariovisic (2013-05-23 11:53:14+00:00)
Title: Add recording of job queued at times

For monitoring Sidekiq i'd like to measure how long the oldest job has been waiting in the queue. I think this is a better measure than the amount of jobs waiting.

With this patch I can do something like this to work it out:

```ruby
def max_sidekiq_wait_seconds
queues = Sidekiq::Stats.new.queues
wait_times = queues.map do |queue_name, job_count|
if job_count > 0
jobs = Sidekiq::Queue.new(queue_name)
(Time.now - Time.parse(jobs.first.enqueued_at)).to_i
end
end

wait_times.max || 0
end
```

I've added a test for the API class but let me know if you'd like some more unit testing.