class Searchkick::ReindexV2Job

Constants

RECORD_NOT_FOUND_CLASSES

Public Instance Methods

perform(klass, id, method_name = nil) click to toggle source
# File lib/searchkick/reindex_v2_job.rb, line 12
def perform(klass, id, method_name = nil)
  model = klass.constantize
  record =
    begin
      if model.respond_to?(:unscoped)
        model.unscoped.find(id)
      else
        model.find(id)
      end
    rescue => e
      # check by name rather than rescue directly so we don't need
      # to determine which classes are defined
      raise e unless RECORD_NOT_FOUND_CLASSES.include?(e.class.name)
      nil
    end

  unless record
    record = model.new
    record.id = id
  end

  RecordIndexer.new(record).reindex(method_name, mode: true)
end