Class: Searchkick::ProcessQueueJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/searchkick/process_queue_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(class_name:, index_name: nil, inline: false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/searchkick/process_queue_job.rb', line 5

def perform(class_name:, index_name: nil, inline: false)
  model = Searchkick.load_model(class_name)
  index = model.searchkick_index(name: index_name)
  limit = model.searchkick_options[:batch_size] || 1000

  loop do
    record_ids = index.reindex_queue.reserve(limit: limit)
    if record_ids.any?
      batch_options = {
        class_name: class_name,
        record_ids: record_ids.uniq,
        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