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", "Cequel::Record::RecordNotFound" ]
Instance Method Summary collapse
Instance Method Details
#perform(klass, id, method_name = nil, routing: nil) ⇒ Object
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 37 38 39 |
# File 'lib/searchkick/reindex_v2_job.rb', line 12 def perform(klass, id, method_name = nil, routing: 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 if routing record.define_singleton_method(:search_routing) do routing end end end RecordIndexer.new(record).reindex(method_name, mode: :inline) end |