lib/openwfe/expressions/fe_do.rb in openwferu-0.9.7 vs lib/openwfe/expressions/fe_do.rb in openwferu-0.9.8

- old
+ new

@@ -37,64 +37,134 @@ # "made in Japan" # # John Mettraux at openwfe.org # +require 'openwfe/utils' require 'openwfe/expressions/flowexpression' # -# do / redo / undo +# redo / undo (cancel) # module OpenWFE # - # in preparation. + # Every expression in OpenWFEru accepts a 'tag' attribute. This tag + # can later be referenced by an 'undo' or 'redo' expression. + # Tags are active as soon as an expression is applied and they vanish + # when the expression replies to its parent expression or is cancelled. # - class DoExpression < FlowExpression + # Calling for the undo of a non-existent tag throws no error, the flow + # simply resumes. + # + # concurrence do + # sequence :tag => "side_job" do + # participant "alice" + # participant "bob" + # end + # sequence do + # participant "charly" + # undo :ref => "side_job" + # end + # end + # + # In this example, as soon as the participant charly is over, the sequence + # 'side_job' gets undone (cancelled). If the sequence 'side_job' was + # already over, the "undo" will have no effect. + # + class UndoExpression < FlowExpression - attr_accessor \ - :name + names :undo - # - # apply / reply - def apply (workitem) - end - def reply (workitem) - end - end + tag = lookup_tag(workitem) - # - # in preparation. - # - class UndoExpression < FlowExpression + undo_self = false + if tag + #OpenWFE::call_in_thread(fei.expression_name, self) do + process_tag(tag) + #end + + undo_self = tag.fei.ancestor_of?(@fei) + end + + reply_to_parent(workitem) unless undo_self + end + # - # apply / reply + # Calls the expression pool cancel() method upon the tagged + # expression. + # + def process_tag (tag) - def apply (workitem) + ldebug do + "process_tag() #{fei.to_debug_s} to undo #{tag.fei.to_debug_s}" + end + + #get_expression_pool.cancel_and_reply_to_parent( + # tag.raw_expression.fei, tag.workitem) + + exp = get_expression_pool.fetch_expression(tag.raw_expression.fei) + + get_expression_pool.cancel(tag.raw_expression.fei) + + get_expression_pool.reply_to_parent(exp, tag.workitem, false) + # + # 'remove' is set to false, cancel already removed the + # expression end #def reply (workitem) #end + + protected + + def lookup_tag (workitem) + + tagname = lookup_attribute(:ref, workitem) + + tag = lookup_variable(tagname) + + lwarn { "lookup_tag() no tag named '#{tagname}' found" } \ + unless tag + + tag + end end # - # in preparation. + # Every expression in OpenWFEru accepts a 'tag' attribute. This tag + # can later be referenced by an 'undo' or 'redo' expression. # - class RedoExpression < FlowExpression + # Calling for the undo of a non-existent tag throws no error, the flow + # simply resumes. + # + class RedoExpression < UndoExpression - # - # apply / reply + names :redo - def apply (workitem) - end + def process_tag (tag) - #def reply (workitem) - #end + ldebug do + "process_tag() #{fei.to_debug_s} to redo #{tag.fei.to_debug_s}" + end + + # + # cancel + + get_expression_pool.cancel(tag.fei) + + # + # [re]apply + + tag.raw_expression.application_context = @application_context + + get_expression_pool.apply(tag.raw_expression, tag.workitem) + end end end