Class: OpenWFE::BlockParticipant
- Inherits:
-
Object
- Object
- OpenWFE::BlockParticipant
- Includes:
- LocalParticipant
- Defined in:
- lib/openwfe/participants/participants.rb
Overview
This participant is used by the register_participant() method of Engine class.
engine.register_participant("the_boss") do |workitem|
puts "the boss received a workitem"
end
After the block executes, the BlockParticipant immediately replies to the engine.
You can pass a block with two arguments : flow_expression and workitem to BlockParticipant, it will automatically adapt.
engine.register_participant("the_boss") do |fexp, wi|
puts "the boss received a workitem from exp #{fexp.fei.to_s}"
end
Having the FlowExpression instance at hand allows for advanced tricks, beware…
It’s also OK to register a block participant without params :
engine.register_participant :alice do
puts "Alice received a workitem"
end
Instance Attribute Summary
Attributes included from Contextual
Instance Method Summary collapse
- #consume(workitem) ⇒ Object
-
#initialize(block0 = nil, &block1) ⇒ BlockParticipant
constructor
A new instance of BlockParticipant.
Methods included from LocalParticipant
#call_block, #get_flow_expression, #reply_to_engine
Methods included from Contextual
#get_work_directory, #init_service, #lookup
Methods included from Logging
#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn
Methods included from OwfeServiceLocator
#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator
Constructor Details
#initialize(block0 = nil, &block1) ⇒ BlockParticipant
Returns a new instance of BlockParticipant.
159 160 161 162 163 164 165 166 167 |
# File 'lib/openwfe/participants/participants.rb', line 159 def initialize (block0=nil, &block1) @block = if block1 block1 else block0 end raise "Missing a block parameter" \ unless @block end |
Instance Method Details
#consume(workitem) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/openwfe/participants/participants.rb', line 169 def consume (workitem) result = call_block @block, workitem workitem.set_result(result) \ if result and result != workitem reply_to_engine(workitem) \ if workitem.kind_of? InFlowWorkItem # else it's a cancel ite end |