1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Add Sidekiq::Queue#latency

This commit is contained in:
Mike Perham 2013-05-23 22:58:06 -07:00
parent 273cdaec10
commit 7f51db4ee3
4 changed files with 19 additions and 5 deletions

View file

@ -2,7 +2,9 @@ HEAD
-----------
- Record the timestamp when jobs are enqueued. Add
Sidekiq::Stats::Job#enqueued_at to query the time. [mariovisic, #944]
Sidekiq::Job#enqueued\_at to query the time. [mariovisic, #944]
- Add Sidekiq::Queue#latency - calculates diff between now and
enqueued\_at for the oldest job in the queue.
2.12.0
-----------

View file

@ -128,6 +128,14 @@ module Sidekiq
Sidekiq.redis { |con| con.llen(@rname) }
end
def latency
entry = Sidekiq.redis do |conn|
conn.lrange(@rname, -1, -1)
end.first
return 0 unless entry
Time.now.to_f - Sidekiq.load_json(entry)['enqueued_at']
end
def each(&block)
page = 0
page_size = 50

View file

@ -1,3 +1,3 @@
module Sidekiq
VERSION = "2.12.0"
VERSION = "2.12.1"
end

View file

@ -164,6 +164,7 @@ class TestApi < Minitest::Test
it 'shows queue as empty' do
q = Sidekiq::Queue.new
assert_equal 0, q.size
assert_equal 0, q.latency
end
class ApiWorker
@ -171,8 +172,8 @@ class TestApi < Minitest::Test
end
it 'can enumerate jobs' do
q = Sidekiq::Queue.new
Time.stub(:now, Time.new(2012, 12, 26)) do
q = Sidekiq::Queue.new
ApiWorker.perform_async(1, 'mike')
assert_equal ['TestApi::ApiWorker'], q.map(&:klass)
@ -181,9 +182,12 @@ class TestApi < Minitest::Test
assert_equal [1, 'mike'], job.args
assert_equal Time.new(2012, 12, 26), job.enqueued_at
q = Sidekiq::Queue.new('other')
assert_equal 0, q.size
end
assert q.latency > 10_000_000
q = Sidekiq::Queue.new('other')
assert_equal 0, q.size
end
it 'can delete jobs' do