lib/searchkick/process_queue_job.rb in searchkick-4.0.2 vs lib/searchkick/process_queue_job.rb in searchkick-4.1.0

- old
+ new

@@ -1,23 +1,31 @@ module Searchkick class ProcessQueueJob < ActiveJob::Base queue_as { Searchkick.queue_name } - def perform(class_name:) + def perform(class_name:, index_name: nil, inline: false) model = class_name.constantize + limit = model.searchkick_options[:batch_size] || 1000 - limit = model.searchkick_index.options[:batch_size] || 1000 - record_ids = model.searchkick_index.reindex_queue.reserve(limit: limit) - if record_ids.any? - Searchkick::ProcessBatchJob.perform_later( - class_name: model.name, - record_ids: record_ids - ) - # TODO when moving to reliable queuing, mark as complete + loop do + record_ids = model.searchkick_index(name: index_name).reindex_queue.reserve(limit: limit) + if record_ids.any? + batch_options = { + class_name: class_name, + record_ids: record_ids, + index_name: index_name + } - if record_ids.size == limit - Searchkick::ProcessQueueJob.perform_later(class_name: class_name) + if inline + # use new.perform to avoid excessive logging + Searchkick::ProcessBatchJob.new.perform(**batch_options) + else + Searchkick::ProcessBatchJob.perform_later(**batch_options) + end + + # TODO when moving to reliable queuing, mark as complete end + break unless record_ids.size == limit end end end end