mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Sort busy workers by run_at, fixes #4641
We sort oldest first so long-running jobs will appear at the top; those jobs are typically the ones that developers want to see and diagnose.
This commit is contained in:
parent
374703e914
commit
2139254f77
2 changed files with 6 additions and 3 deletions
|
@ -916,7 +916,8 @@ module Sidekiq
|
|||
class Workers
|
||||
include Enumerable
|
||||
|
||||
def each
|
||||
def each(&block)
|
||||
results = []
|
||||
Sidekiq.redis do |conn|
|
||||
procs = conn.sscan_each("processes").to_a
|
||||
procs.sort.each do |key|
|
||||
|
@ -930,10 +931,12 @@ module Sidekiq
|
|||
p = hsh["payload"]
|
||||
# avoid breaking API, this is a side effect of the JSON optimization in #4316
|
||||
hsh["payload"] = Sidekiq.load_json(p) if p.is_a?(String)
|
||||
yield key, tid, hsh
|
||||
results << [key, tid, hsh]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
results.sort_by { |(_, _, hsh)| hsh["run_at"] }.each(&block)
|
||||
end
|
||||
|
||||
# Note that #size is only as accurate as Sidekiq's heartbeat,
|
||||
|
|
|
@ -602,7 +602,7 @@ describe 'API' do
|
|||
end
|
||||
end
|
||||
|
||||
assert_equal ['1234', '5678'], w.map { |_, tid, _| tid }
|
||||
assert_equal ['5678', '1234'], w.map { |_, tid, _| tid }
|
||||
end
|
||||
|
||||
it 'can reschedule jobs' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue