Sha256: 342bbd6fe663878620722d6f82ea4d63674b5ca4ae0dfb097654b62c376d8a5d

Contents?: true

Size: 590 Bytes

Versions: 3

Compression:

Stored size: 590 Bytes

Contents

module Searchkick
  class ReindexJob

    def initialize(klass, id)
      @klass = klass
      @id = id
    end

    def perform
      model = @klass.constantize
      record = model.find(@id) rescue nil # TODO fix lazy coding
      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

3 entries across 3 versions & 2 rubygems

Version Path
searchkick-0.9.1 lib/searchkick/reindex_job.rb
searchkick-sinneduy-0.9.0 lib/searchkick/reindex_job.rb
searchkick-0.9.0 lib/searchkick/reindex_job.rb