Module: Auxilium::Concerns::SidekiqCallbacks

Extended by:
ActiveSupport::Concern
Defined in:
lib/auxilium/concerns/sidekiq_callbacks.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/auxilium/concerns/sidekiq_callbacks.rb', line 10

def self.prepended(base)
  base.include(ActiveSupport::Callbacks)

  # Check to see if we already have any callbacks for :perform
  # Prevents overwriting callbacks if we already included this module (and defined callbacks)
  base.define_callbacks :perform unless base.respond_to?(:_perform_callbacks) && base._perform_callbacks.present?
  base.define_callbacks :enqueue unless base.respond_to?(:_enqueue_callbacks) && base._enqueue_callbacks.present?

  class << base
    prepend ClassMethods
  end
end

Instance Method Details

#enqueue(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/auxilium/concerns/sidekiq_callbacks.rb', line 33

def enqueue(*args)
  if respond_to?(:run_callbacks)
    run_callbacks :enqueue do
      super(*args)
    end
  else
    super(*args)
  end
end

#perform(*args) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/auxilium/concerns/sidekiq_callbacks.rb', line 23

def perform(*args)
  if respond_to?(:run_callbacks)
    run_callbacks :perform do
      super(*args)
    end
  else
    super(*args)
  end
end