search_index_job.rb 508 B

12345678910111213141516171819202122232425
  1. class SearchIndexJob < ApplicationJob
  2. retry_on StandardError, attempts: 20, wait: lambda { |executions|
  3. executions * 10.seconds
  4. }
  5. def perform(object, o_id)
  6. @object = object
  7. @o_id = o_id
  8. record = @object.constantize.lookup(id: @o_id)
  9. return if !exists?(record)
  10. record.search_index_update_backend
  11. end
  12. private
  13. def exists?(record)
  14. return true if record
  15. Rails.logger.info "Can't index #{@object}.lookup(id: #{@o_id}), no such record found"
  16. false
  17. end
  18. end