Class: Searchkick::ReindexV2Job
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- Searchkick::ReindexV2Job
- Defined in:
- lib/searchkick/reindex_v2_job.rb
Constant Summary collapse
- RECORD_NOT_FOUND_CLASSES =
[ "ActiveRecord::RecordNotFound", "Mongoid::Errors::DocumentNotFound", "NoBrainer::Error::DocumentNotFound" ]
Instance Method Summary collapse
Instance Method Details
#perform(klass, id) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/searchkick/reindex_v2_job.rb', line 11 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 |