Class: Workarea::IndexAdminSearch

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::CallbacksWorker, Sidekiq::Worker
Defined in:
app/workers/workarea/index_admin_search.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.perform(model) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/workers/workarea/index_admin_search.rb', line 22

def self.perform(model)
  search_model = Search::Admin.for(model)
  return false if search_model.blank?

  if model.persisted? && search_model.should_be_indexed?
    # For the admin, we don't want to index release changes
    Release.with_current(nil) { model.reload } if Release.current.present?

    search_model.save
  else
    search_model.try(:destroy) rescue nil # It's OK if it doesn't exist
  end
end

.should_enqueue?(model) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'app/workers/workarea/index_admin_search.rb', line 17

def self.should_enqueue?(model)
  search_model = Search::Admin.for(model)
  search_model.present? && search_model.should_be_indexed?
end

Instance Method Details

#perform(class_name, id) ⇒ Object



36
37
38
39
# File 'app/workers/workarea/index_admin_search.rb', line 36

def perform(class_name, id)
  model = class_name.constantize.find_or_initialize_by(id: id)
  self.class.perform(model)
end