Class: DaemonKit::RuotePseudoParticipant
- Defined in:
- lib/daemon_kit/ruote_pseudo_participant.rb
Overview
Common convenience methods for making ruote pseudo-participants more DRY and unified
Direct Known Subclasses
Class Attribute Summary collapse
-
.exception_handler_block ⇒ Object
readonly
Returns the value of attribute exception_handler_block.
-
.exception_handler_method ⇒ Object
readonly
Returns the value of attribute exception_handler_method.
-
.on_complete_handler_block ⇒ Object
readonly
Returns the value of attribute on_complete_handler_block.
-
.on_complete_handler_method ⇒ Object
readonly
Returns the value of attribute on_complete_handler_method.
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Current action.
-
#workitem ⇒ Object
readonly
Current workitem.
Class Method Summary collapse
-
.on_complete(handler = nil, &block) ⇒ Object
Register a callback method or block that gets called when the action was successfully completed.
-
.on_exception(handler = nil, &block) ⇒ Object
Register a callback method or block that gets called when an exception occurs during the processing of an action.
Instance Method Summary collapse
- #handle_exception(e) ⇒ Object
-
#perform(action, workitem) ⇒ Object
Perform the specified action with the provided workitem.
- #run_callbacks ⇒ Object
Class Attribute Details
.exception_handler_block ⇒ Object (readonly)
Returns the value of attribute exception_handler_block.
8 9 10 |
# File 'lib/daemon_kit/ruote_pseudo_participant.rb', line 8 def exception_handler_block @exception_handler_block end |
.exception_handler_method ⇒ Object (readonly)
Returns the value of attribute exception_handler_method.
8 9 10 |
# File 'lib/daemon_kit/ruote_pseudo_participant.rb', line 8 def exception_handler_method @exception_handler_method end |
.on_complete_handler_block ⇒ Object (readonly)
Returns the value of attribute on_complete_handler_block.
8 9 10 |
# File 'lib/daemon_kit/ruote_pseudo_participant.rb', line 8 def on_complete_handler_block @on_complete_handler_block end |
.on_complete_handler_method ⇒ Object (readonly)
Returns the value of attribute on_complete_handler_method.
8 9 10 |
# File 'lib/daemon_kit/ruote_pseudo_participant.rb', line 8 def on_complete_handler_method @on_complete_handler_method end |
Instance Attribute Details
#action ⇒ Object (readonly)
Current action
34 35 36 |
# File 'lib/daemon_kit/ruote_pseudo_participant.rb', line 34 def action @action end |
#workitem ⇒ Object (readonly)
Current workitem
31 32 33 |
# File 'lib/daemon_kit/ruote_pseudo_participant.rb', line 31 def workitem @workitem end |
Class Method Details
.on_complete(handler = nil, &block) ⇒ Object
Register a callback method or block that gets called when the action was successfully completed. Block callbacks get the workitem as parameter.
24 25 26 27 |
# 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) ⇒ Object
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
16 17 18 19 |
# 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 |
Instance Method Details
#handle_exception(e) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# 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) ⇒ Object
Perform the specified action with the provided workitem
37 38 39 40 41 42 43 44 45 46 |
# 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 ⇒ Object
58 59 60 61 62 63 64 65 66 |
# 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 |