Sha256: 648942a44682ff646f40feced4ad9c8e268bb6bd463dbfe68c228d343657dfb9
Contents?: true
Size: 1.14 KB
Versions: 25
Compression:
Stored size: 1.14 KB
Contents
module Workarea class IndexAdminSearch include Sidekiq::Worker include Sidekiq::CallbacksWorker sidekiq_options( queue: 'low', lock: :until_executing, query_cache: true, enqueue_on: { ApplicationDocument => [:save, :touch, :destroy], with: -> { [self.class.name, id] }, ignore_if: -> { !IndexAdminSearch.should_enqueue?(self) } } ) def self.should_enqueue?(model) search_model = Search::Admin.for(model) search_model.present? && search_model.should_be_indexed? end 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 def perform(class_name, id) model = class_name.constantize.find_or_initialize_by(id: id) self.class.perform(model) end end end
Version data entries
25 entries across 25 versions & 1 rubygems