lib/ruote/exp/flowexpression.rb in ruote-2.1.9 vs lib/ruote/exp/flowexpression.rb in ruote-2.1.10
- old
+ new
@@ -29,12 +29,32 @@
module Ruote::Exp
#
- # TODO : document me
+ # Ruote is a process definition interpreter. It doesn't directly "read"
+ # process definitions, it relies on a parser/generator to produce "abstract
+ # syntax trees" that look like
#
+ # [ expression_name, { ... attributes ... }, [ children_expressions ] ]
+ #
+ # The nodes (and leaves) in the trees are expressions. This is the base
+ # class for all expressions.
+ #
+ # The most visible expressions are "define", "sequence" and "participant".
+ # Think :
+ #
+ # pdef = Ruote.process_definition do
+ # sequence do
+ # participant :ref => 'customer'
+ # participant :ref => 'accounting'
+ # participant :ref => 'logistics'
+ # end
+ # end
+ #
+ # Each node is an expression...
+ #
class FlowExpression
include Ruote::WithH
include Ruote::WithMeta
@@ -388,13 +408,18 @@
end
def do_fail (msg)
@h['state'] = 'failing'
- persist_or_raise
+ @h['applied_workitem'] = msg['workitem']
- h.children.each { |i| @context.storage.put_msg('cancel', 'fei' => i) }
+ if h.children.size < 1
+ reply_to_parent(@h['applied_workitem'])
+ else
+ persist_or_raise
+ h.children.each { |i| @context.storage.put_msg('cancel', 'fei' => i) }
+ end
end
#--
# misc
#++
@@ -447,10 +472,11 @@
self
elsif h.parent_id
par = parent
+ # :( get_parent would probably be a better name for #parent
unless par
puts "~~"
puts "parent gone for"
p h.fei
@@ -467,11 +493,11 @@
end
end
# Looks up parent with on_error attribute and triggers it
#
- def handle_on_error
+ def handle_on_error (msg, error)
return false if h.state == 'failing'
oe_parent = lookup_on_error
@@ -481,14 +507,19 @@
handler = oe_parent.on_error.to_s
return false if handler == ''
# 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 ]
+
@context.storage.put_msg(
'fail',
'fei' => oe_parent.h.fei,
- 'error_fei' => h.fei)
+ 'workitem' => workitem)
true # yes, error is being handled.
end
#--
@@ -683,9 +714,10 @@
# 'on_{error|timeout|cancel}' triggering
#
def trigger (on, workitem)
hon = h[on]
+
t = hon.is_a?(String) ? [ hon, {}, [] ] : hon
if on == 'on_error'
if hon == 'redo'