Commit f6f637ffd4ba4ad4e594a7cbc898276b7e31ea65
1 parent
8cd48234
Exists in
master
and in
16 other branches
Added inline option to ProcessQueueJob [skip ci]
Showing
1 changed file
with
11 additions
and
3 deletions
Show diff stats
lib/searchkick/process_queue_job.rb
@@ -2,17 +2,25 @@ module Searchkick | @@ -2,17 +2,25 @@ module Searchkick | ||
2 | class ProcessQueueJob < ActiveJob::Base | 2 | class ProcessQueueJob < ActiveJob::Base |
3 | queue_as { Searchkick.queue_name } | 3 | queue_as { Searchkick.queue_name } |
4 | 4 | ||
5 | - def perform(class_name:) | 5 | + def perform(class_name:, inline: false) |
6 | model = class_name.constantize | 6 | model = class_name.constantize |
7 | limit = model.searchkick_options[:batch_size] || 1000 | 7 | limit = model.searchkick_options[:batch_size] || 1000 |
8 | 8 | ||
9 | loop do | 9 | loop do |
10 | record_ids = model.searchkick_index.reindex_queue.reserve(limit: limit) | 10 | record_ids = model.searchkick_index.reindex_queue.reserve(limit: limit) |
11 | if record_ids.any? | 11 | if record_ids.any? |
12 | - Searchkick::ProcessBatchJob.perform_later( | 12 | + batch_options = { |
13 | class_name: class_name, | 13 | class_name: class_name, |
14 | record_ids: record_ids | 14 | record_ids: record_ids |
15 | - ) | 15 | + } |
16 | + | ||
17 | + if inline | ||
18 | + # use new.perform to avoid excessive logging | ||
19 | + Searchkick::ProcessBatchJob.new.perform(**batch_options) | ||
20 | + else | ||
21 | + Searchkick::ProcessBatchJob.perform_later(**batch_options) | ||
22 | + end | ||
23 | + | ||
16 | # TODO when moving to reliable queuing, mark as complete | 24 | # TODO when moving to reliable queuing, mark as complete |
17 | end | 25 | end |
18 | break unless record_ids.size == limit | 26 | break unless record_ids.size == limit |