Skip to content

Commit

Permalink
refactor stat method
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Jul 6, 2021
1 parent a2c7541 commit 465c5c6
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/sidekiq/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ def fetch_stats_fast!
end
}


default_queue_latency = if (entry = pipe1_res[6].first)
job = begin
Sidekiq.load_json(entry)
rescue
{}
end
Sidekiq.load_json(entry)
rescue
{}
end
now = Time.now.to_f
thence = job["enqueued_at"] || now
now - thence
Expand Down Expand Up @@ -138,11 +137,8 @@ def reset(*stats)
private

def stat(s)
if (s == :enqueued || s == :workers_size) &&
@stats.present? && @stats[s].nil?
fetch_stats_slow!
end
@stats[s]
fetch_stats_slow! if @stats[s].nil?
@stats[s] || raise(ArgumentError, "Unknown stat #{s}")
end

class Queues
Expand Down

0 comments on commit 465c5c6

Please sign in to comment.