lib/openwfe/participants/participants.rb in openwferu-0.9.3 vs lib/openwfe/participants/participants.rb in openwferu-0.9.4
- old
+ new
@@ -78,23 +78,46 @@
# 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...
+ #
class BlockParticipant
include LocalParticipant
- def initialize (block)
- @block = block
+ def initialize (block0=nil, &block1)
+ @block = if block1
+ block1
+ else
+ block0
+ end
+ raise "Missing a block parameter" \
+ unless @block
end
def consume (workitem)
- @block.call workitem
+ if @block.arity == 1
+ @block.call workitem
+ elsif @block.arity > 1
+ @block.call get_flow_expression(workitem), workitem
+ else
+ @block.call
+ end
reply_to_engine(workitem) \
if workitem.kind_of? InFlowWorkItem
# else it's a cancel item
end
end
+
end