Class: Searchkick::ReindexJob

Inherits:
Object
  • Object
show all
Defined in:
lib/searchkick/reindex_job.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, id) ⇒ ReindexJob

Returns a new instance of ReindexJob.



3
4
5
6
# File 'lib/searchkick/reindex_job.rb', line 3

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

Instance Method Details

#performObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/searchkick/reindex_job.rb', line 8

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