lib/ruote/exp/flowexpression.rb in ruote-2.1.10 vs lib/ruote/exp/flowexpression.rb in ruote-2.1.11

- old
+ new

@@ -22,11 +22,10 @@ # Made in Japan. #++ require 'ruote/util/time' require 'ruote/util/ometa' -require 'ruote/util/dollar' require 'ruote/util/hashdot' module Ruote::Exp @@ -118,11 +117,11 @@ def parent Ruote::Exp::FlowExpression.fetch(@context, h.parent_id) end # Turns this FlowExpression instance into a Hash (well, just hands back - # the base hash behind it. + # the base hash behind it). # def to_h @h end @@ -167,21 +166,29 @@ fei = msg['fei'] action = msg['action'] if action == 'reply' && fei['engine_id'] != context.engine_id + # + # the reply has to go to another engine, let's locate the + # 'engine participant' and give it the workitem/reply + # + # see ft_37 for a test/example - ep = context.plist.lookup(fei['engine_id']) + engine_participant = + context.plist.lookup(fei['engine_id'], msg['workitem']) raise( "no EngineParticipant found under name '#{fei['engine_id']}'" - ) unless ep + ) unless engine_participant - ep.reply(fei, msg['workitem']) + engine_participant.reply(fei, msg['workitem']) return end + # normal case + fexp = nil 3.times do fexp = fetch(context, msg['fei']) break if fexp @@ -238,10 +245,14 @@ elsif (h.state == 'cancelling') and h.on_cancel trigger('on_cancel', workitem) + elsif (h.state == 'cancelling') and h.on_re_apply + + trigger('on_re_apply', workitem) + elsif (h.state == 'timing_out') and h.on_timeout trigger('on_timeout', workitem) else # vanilla reply @@ -344,11 +355,13 @@ h.on_cancel = t elsif hra = msg['re_apply'] hra = {} if hra == true - h.on_cancel = hra['tree'] || tree + + h.on_re_apply = hra['tree'] || tree + if fs = hra['fields'] h.applied_workitem['fields'] = fs end if mfs = hra['merge_in_fields'] h.applied_workitem['fields'].merge!(mfs) @@ -510,11 +523,11 @@ # empty on_error handler nullifies ancestor's on_error workitem = msg['workitem'] workitem['fields']['__error__'] = [ - h.fei, Ruote.now_to_utc_s, error.class.to_s, error.message ] + h.fei, Ruote.now_to_utc_s, error.class.to_s, error.message, error.backtrace ] @context.storage.put_msg( 'fail', 'fei' => oe_parent.h.fei, 'workitem' => workitem) @@ -654,11 +667,11 @@ @context.storage.put_msg( 'entered_tag', 'tag' => h.tagname, 'fei' => h.fei) end end - # Called by do_apply. Overriden in ParticipantExpression. + # Called by do_apply. Overriden in ParticipantExpression and RefExpression. # def consider_timeout do_schedule_timeout(attribute(:timeout)) end @@ -667,14 +680,12 @@ # (ParticipantExpression). # def do_schedule_timeout (timeout) return unless timeout + return if timeout.strip == '' - #h.timeout_at = Ruote.s_to_at(timeout) - #return if not(h.timeout_at) || h.timeout_at < Time.now.utc + 1.0 - h.timeout_schedule_id = @context.storage.put_schedule( 'at', h.fei, timeout, 'action' => 'cancel', @@ -709,10 +720,10 @@ 'workitem' => h.applied_workitem, 'variables' => h.variables }.merge!(opts)) end - # 'on_{error|timeout|cancel}' triggering + # 'on_{error|timeout|cancel|re_apply}' triggering # def trigger (on, workitem) hon = h[on]