mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Speedup iterating over WorkSet
(#5559)
This commit is contained in:
parent
d424e45328
commit
7037533e8f
1 changed files with 19 additions and 12 deletions
|
@ -1103,15 +1103,23 @@ module Sidekiq
|
|||
|
||||
def each(&block)
|
||||
results = []
|
||||
procs = nil
|
||||
all_works = nil
|
||||
|
||||
Sidekiq.redis do |conn|
|
||||
procs = conn.sscan_each("processes").to_a
|
||||
procs.sort.each do |key|
|
||||
valid, workers = conn.pipelined { |pipeline|
|
||||
pipeline.exists?(key)
|
||||
procs = conn.sscan_each("processes").to_a.sort
|
||||
|
||||
all_works = conn.pipelined do |pipeline|
|
||||
procs.each do |key|
|
||||
pipeline.hgetall("#{key}:work")
|
||||
}
|
||||
next unless valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
procs.zip(all_works).each do |key, workers|
|
||||
workers.each_pair do |tid, json|
|
||||
next if json.empty?
|
||||
|
||||
hsh = Sidekiq.load_json(json)
|
||||
p = hsh["payload"]
|
||||
# avoid breaking API, this is a side effect of the JSON optimization in #4316
|
||||
|
@ -1119,7 +1127,6 @@ module Sidekiq
|
|||
results << [key, tid, hsh]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
results.sort_by { |(_, _, hsh)| hsh["run_at"] }.each(&block)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue