6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/sidekiq/routing/auto/batch_rerouter.rb', line 6
def reroute_jobs(from_queue, to_queue, job_classes: nil)
limit = Routing::Auto.configuration.batch_reroute_limit
moved_count = 0
skipped = { already_rerouted: 0, wrong_class: 0, excluded: 0 }
queue = Sidekiq::Queue.new(from_queue)
Routing::Auto.logger.info(
"[Routing::Auto] reroute_jobs: from=#{from_queue}, to=#{to_queue}, " \
"limit=#{limit}, job_classes=#{job_classes.inspect}"
)
queue.each do |job|
break if moved_count >= limit
if job.item["auto_rerouted"]
skipped[:already_rerouted] += 1
next
end
if job_classes && !job_classes.include?(job.klass)
skipped[:wrong_class] += 1
next
end
if Routing::Auto.configuration.excluded_job_classes.include?(job.klass)
skipped[:excluded] += 1
next
end
moved_count += 1 if reroute_single_job(job, from_queue, to_queue)
end
Routing::Auto.logger.info(
"[Routing::Auto] reroute_jobs: moved=#{moved_count}, skipped=#{skipped.inspect}"
)
log_reroute(from_queue, to_queue, moved_count, job_classes) if moved_count.positive?
moved_count
end
|