class DaemonKit::RuotePseudoParticipant
Common convenience methods for making ruote pseudo-participants more DRY and unified
Attributes
exception_handler_block[R]
exception_handler_method[R]
on_complete_handler_block[R]
on_complete_handler_method[R]
action[R]
Current action
workitem[R]
Current workitem
Public Class Methods
on_complete( handler = nil, &block )
click to toggle source
Register a callback method or block that gets called when the action was successfully completed. Block callbacks get the workitem as parameter.
# File lib/daemon_kit/ruote_pseudo_participant.rb, line 24 def on_complete( handler = nil, &block ) @on_complete_handler_method = handler @on_complete_handler_block = block end
on_exception( handler = nil, &block )
click to toggle source
Register a callback method or block that gets called when an exception occurs during the processing of an action. handler
can be a symbol or string with a method name, or a block. Both will get the exception as the first parameter, and the block handler will receive the participant instance as the second parameter
# File lib/daemon_kit/ruote_pseudo_participant.rb, line 16 def on_exception( handler = nil, &block ) @exception_handler_method = handler @exception_handler_block = block end
Public Instance Methods
handle_exception( e )
click to toggle source
# File lib/daemon_kit/ruote_pseudo_participant.rb, line 48 def handle_exception( e ) raise e if self.class.exception_handler_method.nil? && self.class.exception_handler_block.nil? if self.class.exception_handler_method send( self.class.exception_handler_method, e ) else self.class.exception_handler_block.call( e, self ) end end
perform( action, workitem )
click to toggle source
Perform the specified action with the provided workitem
# File lib/daemon_kit/ruote_pseudo_participant.rb, line 37 def perform( action, workitem ) @action, @workitem = action, workitem begin send( action ) run_callbacks rescue => e handle_exception( e ) end end
run_callbacks()
click to toggle source
# File lib/daemon_kit/ruote_pseudo_participant.rb, line 58 def run_callbacks return if self.class.on_complete_handler_block.nil? && self.class.on_complete_handler_method.nil? if self.class.on_complete_handler_method send( self.class.on_complete_handler_method ) else self.class.on_complete_handler_block.call( workitem ) end end