Class: Delayed::Lifecycle
- Inherits:
-
Object
- Object
- Delayed::Lifecycle
- Defined in:
- lib/delayed/lifecycle.rb
Constant Summary collapse
- EVENTS =
{ :error => [:worker, :job, :exception], :exceptional_exit => [:worker, :exception], :execute => [:worker], :invoke_job => [:job], :loop => [:worker], :perform => [:worker, :job], :pop => [:worker], :work_queue_pop => [:work_queue, :worker_config], }
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.
16 17 18 |
# File 'lib/delayed/lifecycle.rb', line 16 def initialize reset! end |
Instance Method Details
#after(event, &block) ⇒ Object
29 30 31 |
# File 'lib/delayed/lifecycle.rb', line 29 def after(event, &block) add(:after, event, &block) end |
#around(event, &block) ⇒ Object
33 34 35 |
# File 'lib/delayed/lifecycle.rb', line 33 def around(event, &block) add(:around, event, &block) end |
#before(event, &block) ⇒ Object
25 26 27 |
# File 'lib/delayed/lifecycle.rb', line 25 def before(event, &block) add(:before, event, &block) end |
#reset! ⇒ Object
20 21 22 23 |
# File 'lib/delayed/lifecycle.rb', line 20 def reset! @callbacks = EVENTS.keys.inject({}) { |hash, e| hash[e] = Callback.new; hash } Delayed::Worker.plugins.each { |plugin| plugin.reset! } end |
#run_callbacks(event, *args, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/delayed/lifecycle.rb', line 37 def run_callbacks(event, *args, &block) missing_callback(event) unless @callbacks.has_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 |