Sha256: a67bcd4fff9900cf56936ae9715f4d0d65437258e52c6a45f1b8557717e2f151

Contents?: true

Size: 1017 Bytes

Versions: 13

Compression:

Stored size: 1017 Bytes

Contents

module Searchkick
  class ReindexV2Job < ActiveJob::Base
    RECORD_NOT_FOUND_CLASSES = [
      "ActiveRecord::RecordNotFound",
      "Mongoid::Errors::DocumentNotFound",
      "NoBrainer::Error::DocumentNotFound",
      "Cequel::Record::RecordNotFound"
    ]

    queue_as { Searchkick.queue_name }

    def perform(klass, id)
      model = klass.constantize
      record =
        begin
          model.find(id)
        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

      index = model.searchkick_index
      if !record || !record.should_index?
        # hacky
        record ||= model.new
        record.id = id
        begin
          index.remove record
        rescue Elasticsearch::Transport::Transport::Errors::NotFound
          # do nothing
        end
      else
        index.store record
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
searchkick-2.5.0 lib/searchkick/reindex_v2_job.rb
searchkick-hooopo-2.4.1 lib/searchkick/reindex_v2_job.rb
searchkick-hooopo-2.4.0 lib/searchkick/reindex_v2_job.rb
searchkick-2.4.0 lib/searchkick/reindex_v2_job.rb
searchkick-hooopo-2.3.5 lib/searchkick/reindex_v2_job.rb
searchkick-2.3.2 lib/searchkick/reindex_v2_job.rb
searchkick-hooopo-2.3.4 lib/searchkick/reindex_v2_job.rb
searchkick-2.3.1 lib/searchkick/reindex_v2_job.rb
searchkick-hooopo-2.3.3 lib/searchkick/reindex_v2_job.rb
searchkick-hooopo-2.3.2 lib/searchkick/reindex_v2_job.rb
searchkick-hooopo-2.3.1 lib/searchkick/reindex_v2_job.rb
searchkick-hooopo-2.3.0 lib/searchkick/reindex_v2_job.rb
searchkick-2.3.0 lib/searchkick/reindex_v2_job.rb