lib/sidekiq/api.rb in sidekiq-5.0.0.beta1 vs lib/sidekiq/api.rb in sidekiq-5.0.0.beta2
- old
+ new
@@ -73,11 +73,14 @@
s = pipe1_res[7].size
workers_size = pipe2_res[0...s].map(&:to_i).inject(0, &:+)
enqueued = pipe2_res[s..-1].map(&:to_i).inject(0, &:+)
default_queue_latency = if (entry = pipe1_res[6].first)
- Time.now.to_f - Sidekiq.load_json(entry)['enqueued_at'.freeze]
+ job = Sidekiq.load_json(entry)
+ now = Time.now.to_f
+ thence = job['enqueued_at'.freeze] || now
+ now - thence
else
0
end
@stats = {
processed: pipe1_res[0].to_i,
@@ -223,11 +226,14 @@
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']
+ job = Sidekiq.load_json(entry)
+ now = Time.now.to_f
+ thence = job['enqueued_at'] || now
+ now - thence
end
def each
initial_size = size
deleted_size = 0
@@ -353,11 +359,12 @@
def queue
@queue
end
def latency
- Time.now.to_f - (self['enqueued_at'] || self['created_at'] || 0)
+ now = Time.now.to_f
+ now - (@item['enqueued_at'] || @item['created_at'] || now)
end
##
# Remove this job from the queue.
def delete
@@ -590,16 +597,16 @@
##
# Allows enumeration of scheduled jobs within Sidekiq.
# Based on this, you can search/filter for jobs. Here's an
# example where I'm selecting all jobs of a certain type
- # and deleting them from the retry queue.
+ # and deleting them from the schedule queue.
#
# r = Sidekiq::ScheduledSet.new
- # r.select do |retri|
- # retri.klass == 'Sidekiq::Extensions::DelayedClass' &&
- # retri.args[0] == 'User' &&
- # retri.args[1] == 'setup_new_subscriber'
+ # r.select do |scheduled|
+ # scheduled.klass == 'Sidekiq::Extensions::DelayedClass' &&
+ # scheduled.args[0] == 'User' &&
+ # scheduled.args[1] == 'setup_new_subscriber'
# end.map(&:delete)
class ScheduledSet < JobSet
def initialize
super 'schedule'
end