Skip to content

Commit

Permalink
keeping track of workitem fields as they were right before a particip…
Browse files Browse the repository at this point in the history
…ant error
  • Loading branch information
jmettraux committed Apr 20, 2010
1 parent 2a94e42 commit 0058881
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -4,6 +4,7 @@

== ruote - 2.1.10 not yet released

- keeping track of workitem fields as they were right before a participant error
- Workitem.error holds the error when on_error. Thanks Oleg.
- Workitem#error and Workitem#timed_out shortcuts
- participant :on_error => 'x' broken. Fixed. Thanks Oleg.
Expand Down
2 changes: 1 addition & 1 deletion TODO.txt
Expand Up @@ -199,7 +199,7 @@
[o] Rdoc Ruote::Engine.register_participant -> passing a block to a participant
and perhaps also on
http://ruote.rubyforge.org/implementing_participants.html (Avish)
[x] wrap workitem in process error ? for on_error consumption (thanks Oleg)
[o] wrap workitem in process error ? for on_error consumption (thanks Oleg)
doing workitem.fields['__error__'] = [ fei, time, error_message ]

[ ] exp : exp (restricted form of eval ?)
Expand Down
12 changes: 8 additions & 4 deletions lib/ruote/exp/flowexpression.rb
Expand Up @@ -390,7 +390,7 @@ def cancel (flavour)
def do_fail (msg)

@h['state'] = 'failing'
@h['applied_workitem']['fields']['__error__'] = msg['error']
@h['applied_workitem'] = msg['workitem']

if h.children.size < 1
reply_to_parent(@h['applied_workitem'])
Expand Down Expand Up @@ -474,7 +474,7 @@ def lookup_on_error

# Looks up parent with on_error attribute and triggers it
#
def handle_on_error (error)
def handle_on_error (msg, error)

return false if h.state == 'failing'

Expand All @@ -488,11 +488,15 @@ def handle_on_error (error)
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' => [
h.fei, Ruote.now_to_utc_s, error.class.to_s, error.message ])
'workitem' => workitem)

true # yes, error is being handled.
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruote/worker.rb
Expand Up @@ -129,7 +129,7 @@ def handle_exception (msg, fexp, ex)
fexp = Ruote::Exp::FlowExpression.fetch(@context, fei)
end

return if fexp && fexp.handle_on_error(ex)
return if fexp && fexp.handle_on_error(msg, ex)

# emit 'msg'

Expand Down
14 changes: 8 additions & 6 deletions test/functional/ft_5_on_error.rb
Expand Up @@ -161,13 +161,14 @@ def test_participant_on_error
end
end

error = nil
workitem = nil

@engine.register_participant :troublemaker do
@engine.register_participant :troublemaker do |wi|
wi.fields['seen'] = true
raise 'Beijing, we have a problem !'
end
@engine.register_participant :troublespotter do |workitem|
error = workitem.error
@engine.register_participant :troublespotter do |wi|
workitem = wi
@tracer << 'err...'
end

Expand All @@ -181,8 +182,9 @@ def test_participant_on_error
#puts er.trace

assert_equal 'err...', @tracer.to_s
assert_equal 4, error.size
assert_equal 'RuntimeError', error[2]
assert_equal 4, workitem.error.size
assert_equal 'RuntimeError', workitem.error[2]
assert_equal true, workitem.fields['seen']
end
end

0 comments on commit 0058881

Please sign in to comment.