Sha256: 940fa3aff1f2d522b5b4f44302d2684d55443171f37b4d3aecf598e4f2203fa2
Contents?: true
Size: 1.5 KB
Versions: 21
Compression:
Stored size: 1.5 KB
Contents
module Sidekiq # Mixin for Sidekiq workers that enables the worker to be called via # Rails callback methods. module CallbacksWorker extend ActiveSupport::Concern mattr_accessor :workers self.workers = [] included do thread_cattr_accessor :enabled, :inlined CallbacksWorker.workers << self end class_methods do 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
21 entries across 21 versions & 1 rubygems