Sha256: ead3589b0a06915c1cc07221dfe38d2862a0a837ed36689857c60b133b880104

Contents?: true

Size: 946 Bytes

Versions: 12

Compression:

Stored size: 946 Bytes

Contents

module Searchkick
  class ProcessQueueJob < ActiveJob::Base
    queue_as { Searchkick.queue_name }

    def perform(class_name:, index_name: nil, inline: false)
      model = class_name.constantize
      limit = model.searchkick_options[:batch_size] || 1000

      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 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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
searchkick-4.5.0 lib/searchkick/process_queue_job.rb
searchkick-4.4.4 lib/searchkick/process_queue_job.rb
searchkick-4.4.3 lib/searchkick/process_queue_job.rb
searchkick-4.4.2 lib/searchkick/process_queue_job.rb
searchkick-4.4.1 lib/searchkick/process_queue_job.rb
searchkick-4.4.0 lib/searchkick/process_queue_job.rb
searchkick-4.3.1 lib/searchkick/process_queue_job.rb
searchkick-4.3.0 lib/searchkick/process_queue_job.rb
searchkick-4.2.1 lib/searchkick/process_queue_job.rb
searchkick-4.2.0 lib/searchkick/process_queue_job.rb
searchkick-4.1.1 lib/searchkick/process_queue_job.rb
searchkick-4.1.0 lib/searchkick/process_queue_job.rb