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)
|
def each(&block)
|
||||||
results = []
|
results = []
|
||||||
|
procs = nil
|
||||||
|
all_works = nil
|
||||||
|
|
||||||
Sidekiq.redis do |conn|
|
Sidekiq.redis do |conn|
|
||||||
procs = conn.sscan_each("processes").to_a
|
procs = conn.sscan_each("processes").to_a.sort
|
||||||
procs.sort.each do |key|
|
|
||||||
valid, workers = conn.pipelined { |pipeline|
|
all_works = conn.pipelined do |pipeline|
|
||||||
pipeline.exists?(key)
|
procs.each do |key|
|
||||||
pipeline.hgetall("#{key}:work")
|
pipeline.hgetall("#{key}:work")
|
||||||
}
|
end
|
||||||
next unless valid
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
procs.zip(all_works).each do |key, workers|
|
||||||
workers.each_pair do |tid, json|
|
workers.each_pair do |tid, json|
|
||||||
|
next if json.empty?
|
||||||
|
|
||||||
hsh = Sidekiq.load_json(json)
|
hsh = Sidekiq.load_json(json)
|
||||||
p = hsh["payload"]
|
p = hsh["payload"]
|
||||||
# avoid breaking API, this is a side effect of the JSON optimization in #4316
|
# avoid breaking API, this is a side effect of the JSON optimization in #4316
|
||||||
|
@ -1119,7 +1127,6 @@ module Sidekiq
|
||||||
results << [key, tid, hsh]
|
results << [key, tid, hsh]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
results.sort_by { |(_, _, hsh)| hsh["run_at"] }.each(&block)
|
results.sort_by { |(_, _, hsh)| hsh["run_at"] }.each(&block)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue