Class: Noiseless::SearchIndexUpdateJob
- Inherits:
-
Object
- Object
- Noiseless::SearchIndexUpdateJob
- Defined in:
- lib/noiseless/search_index_update_job.rb
Defined Under Namespace
Classes: DeletedRecord
Class Method Summary collapse
- .perform_later(model_class_name, record_id, operation, options = {}) ⇒ Object
- .perform_now(model_class_name, record_id, operation, options = {}) ⇒ Object
Class Method Details
.perform_later(model_class_name, record_id, operation, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/noiseless/search_index_update_job.rb', line 5 def self.perform_later(model_class_name, record_id, operation, = {}) if defined?(ActiveJob::Base) ActiveJobSearchIndexUpdateJob.perform_later(model_class_name, record_id, operation, ) elsif defined?(Sidekiq) SidekiqSearchIndexUpdateJob.perform_async(model_class_name, record_id, operation, ) else # Fallback to immediate execution perform_now(model_class_name, record_id, operation, ) end end |
.perform_now(model_class_name, record_id, operation, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/noiseless/search_index_update_job.rb', line 16 def self.perform_now(model_class_name, record_id, operation, = {}) model_class = model_class_name.constantize case operation when "update" record = model_class.find(record_id) record.document_manager.update_document(**) when "delete" # For delete operations, we need to construct a minimal object # since the record might already be deleted from the database document_manager = DocumentManager.new( DeletedRecord.new(model_class, record_id) ) document_manager.delete_document(**) else raise ArgumentError, "Unknown operation: #{operation}" end rescue StandardError => e if [:raise_on_error] raise e elsif (logger = Rails.logger) # Log error silently logger.error "Noiseless: Background job failed for #{model_class_name}##{record_id}: #{e.}" end end |