Class: Delayed::Lifecycle
- Inherits:
-
Object
- Object
- Delayed::Lifecycle
- Defined in:
- lib/delayed/lifecycle.rb
Constant Summary collapse
- EVENTS =
{ error: %i[worker job exception], exceptional_exit: %i[worker exception], execute: [:worker], invoke_job: [:job], loop: [:worker], perform: %i[worker job], pop: [:worker], retry: %i[worker job exception], work_queue_pop: %i[work_queue worker_config], check_for_work: [:work_queue] }.freeze
Instance Method Summary collapse
- #after(event, &block) ⇒ Object
- #around(event, &block) ⇒ Object
- #before(event, &block) ⇒ Object
-
#initialize ⇒ Lifecycle
constructor
A new instance of Lifecycle.
- #reset! ⇒ Object
- #run_callbacks(event, *args, &block) ⇒ Object
Constructor Details
#initialize ⇒ Lifecycle
Returns a new instance of Lifecycle.
20 21 22 |
# File 'lib/delayed/lifecycle.rb', line 20 def initialize reset! end |
Instance Method Details
#after(event, &block) ⇒ Object
36 37 38 |
# File 'lib/delayed/lifecycle.rb', line 36 def after(event, &block) add(:after, event, &block) end |
#around(event, &block) ⇒ Object
40 41 42 |
# File 'lib/delayed/lifecycle.rb', line 40 def around(event, &block) add(:around, event, &block) end |
#before(event, &block) ⇒ Object
32 33 34 |
# File 'lib/delayed/lifecycle.rb', line 32 def before(event, &block) add(:before, event, &block) end |
#reset! ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/delayed/lifecycle.rb', line 24 def reset! @callbacks = EVENTS.keys.each_with_object({}) do |e, hash| hash[e] = Callback.new hash end Delayed::Worker.plugins.each(&:reset!) end |
#run_callbacks(event, *args, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/delayed/lifecycle.rb', line 44 def run_callbacks(event, *args, &block) missing_callback(event) unless @callbacks.key?(event) unless EVENTS[event].size == args.size raise ArgumentError, "Callback #{event} expects #{EVENTS[event].size} parameter(s): #{EVENTS[event].join(', ')}" end @callbacks[event].execute(*args, &block) end |