Commit d56fa7ab56a55f3c69255e96cb556a8b9624dbb1
1 parent
ab3de17e
Exists in
master
and in
17 other branches
Cleaner queue code [skip ci]
Showing
1 changed file
with
9 additions
and
10 deletions
Show diff stats
lib/searchkick/process_queue_job.rb
... | ... | @@ -4,19 +4,18 @@ module Searchkick |
4 | 4 | |
5 | 5 | def perform(class_name:) |
6 | 6 | model = class_name.constantize |
7 | - | |
8 | 7 | limit = model.searchkick_index.options[:batch_size] || 1000 |
9 | - record_ids = model.searchkick_index.reindex_queue.reserve(limit: limit) | |
10 | - if record_ids.any? | |
11 | - Searchkick::ProcessBatchJob.perform_later( | |
12 | - class_name: model.name, | |
13 | - record_ids: record_ids | |
14 | - ) | |
15 | - # TODO when moving to reliable queuing, mark as complete | |
16 | 8 | |
17 | - if record_ids.size == limit | |
18 | - Searchkick::ProcessQueueJob.perform_later(class_name: class_name) | |
9 | + loop do | |
10 | + record_ids = model.searchkick_index.reindex_queue.reserve(limit: limit) | |
11 | + if record_ids.any? | |
12 | + Searchkick::ProcessBatchJob.perform_later( | |
13 | + class_name: model.name, | |
14 | + record_ids: record_ids | |
15 | + ) | |
16 | + # TODO when moving to reliable queuing, mark as complete | |
19 | 17 | end |
18 | + break unless record_ids.size == limit | |
20 | 19 | end |
21 | 20 | end |
22 | 21 | end | ... | ... |