Sha256: d918b267e8fe938637225b89fa7167e0b879e49a1595eaf547d4b726d2371ccd
Contents?: true
Size: 1.56 KB
Versions: 41
Compression:
Stored size: 1.56 KB
Contents
module Sidekiq # Mixin for Sidekiq workers that enables the worker to be called via # Rails callback methods. module CallbacksWorker extend ActiveSupport::Concern included do thread_cattr_accessor :enabled, :inlined Sidekiq::Callbacks.add_worker(self) end class_methods do # @deprecated TODO remove this in v3.6 def workers Sidekiq::Callbacks.workers end def enabled? enabled.nil? || !!enabled end def disabled? !enabled? end def enable self.enabled = true end def disable self.enabled = false end def inlined? !!inlined end def inline self.inlined = true end def async self.inlined = false end def enqueue_on get_sidekiq_options['enqueue_on'] || get_sidekiq_options[:enqueue_on] || {} end def callbacks enqueue_on.except(:with, 'with', :ignore_if, 'ignore_if', :only_if, 'only_if') end def find_callback_args(model) with = enqueue_on[:with] || enqueue_on['with'] if with.present? model.instance_exec(&with) else [model.id.to_s] end end def perform_callback?(model) only_if = enqueue_on[:only_if] || enqueue_on['only_if'] ignore_if = enqueue_on[:ignore_if] || enqueue_on['ignore_if'] (only_if.blank? || !!model.instance_exec(&only_if)) && (ignore_if.blank? || !model.instance_exec(&ignore_if)) end end end end
Version data entries
41 entries across 41 versions & 1 rubygems