Commit f6f637ffd4ba4ad4e594a7cbc898276b7e31ea65

Authored by Andrew Kane
1 parent 8cd48234

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 2 class ProcessQueueJob < ActiveJob::Base
3 3 queue_as { Searchkick.queue_name }
4 4  
5   - def perform(class_name:)
  5 + def perform(class_name:, inline: false)
6 6 model = class_name.constantize
7 7 limit = model.searchkick_options[:batch_size] || 1000
8 8  
9 9 loop do
10 10 record_ids = model.searchkick_index.reindex_queue.reserve(limit: limit)
11 11 if record_ids.any?
12   - Searchkick::ProcessBatchJob.perform_later(
  12 + batch_options = {
13 13 class_name: class_name,
14 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 24 # TODO when moving to reliable queuing, mark as complete
17 25 end
18 26 break unless record_ids.size == limit
... ...