Skip to content

Commit

Permalink
implemented on_timeout=error
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Jul 29, 2009
1 parent 6b05e36 commit 14cbcc7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 22 deletions.
5 changes: 3 additions & 2 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@
[o] participant : do thread (and do_not_thread)
[o] add test for error replay in participant
[o] forget : participant ? subprocess ? everybody

[o] on_timeout => 'part|sub' (idea by hassox)
[ ] on_timeout => 'error' (idea by hassox)
[o] on_timeout => 'error' (idea by hassox)

[ ] file logger service

Expand Down Expand Up @@ -133,3 +132,5 @@ restart tests :

[ ] participant : if EM is present use next_ or defer instead of Thread.new

[ ] test for wfids of errors in subprocesses !

33 changes: 31 additions & 2 deletions lib/ruote/exp/flowexpression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@

module Ruote

#
# A simple timeout error. Only used when :on_timeout => 'error' for now.
#
class TimeoutError < RuntimeError
def backtrace
[ '---' ]
end
end

#
# The root class for all the expressions in Ruote.
#
# Contains lots of default behaviour, extending classes primarily
# override #apply, #reply and #cancel.
#
class FlowExpression < ObjectWithMeta

include EngineContext
Expand All @@ -46,7 +61,7 @@ class FlowExpression < ObjectWithMeta

attr_accessor :on_cancel
attr_accessor :on_error
#attr_accessor :on_timeout
attr_accessor :on_timeout

attr_accessor :created_time
attr_accessor :applied_workitem
Expand Down Expand Up @@ -601,7 +616,21 @@ def trigger_on_timeout (workitem)

if handler == 'error'

# which direction for the error ?
# building and emitting an 'artifical' error

message = [ :expressions, :apply, {
:tree => tree,
:fei => @fei,
:workitem => @applied_workitem,
:variables => @variables } ]

wqueue.emit(
:errors,
:s_expression_pool, # somehow...
{ :error => TimeoutError.new(attribute(:timeout)),
:wfid => @fei.wfid, # parent wfid ?
:message => message })

else

apply_tree(
Expand Down
44 changes: 26 additions & 18 deletions test/functional/ft_15_timeout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,6 @@ def test_cancel_timeout
assert_equal 0, @engine.scheduler.jobs.size
end

def _test_on_timeout_error

pdef = Ruote.process_definition do
alpha :timeout => '500', :on_timeout => 'error'
end

alpha = @engine.register_participant :alpha, Ruote::HashParticipant

noisy

wfid = @engine.launch(pdef)
wait_for(wfid)

ps = @engine.process(wfid)

assert_equal 1, ps.errors.size
end

def test_on_timeout_redo

pdef = Ruote.process_definition do
Expand Down Expand Up @@ -129,5 +111,31 @@ def test_on_timeout_cancel_nested
assert_equal 0, @engine.expstorage.size
assert_equal 0, alpha.size
end

def test_on_timeout_error

pdef = Ruote.process_definition do
alpha :timeout => '500', :on_timeout => 'error'
end

alpha = @engine.register_participant :alpha, Ruote::HashParticipant

#noisy

wfid = @engine.launch(pdef)
wait_for(wfid)

ps = @engine.process(wfid)

assert_equal 1, ps.errors.size

err = ps.errors.first
err.tree = [ 'alpha', {}, [] ]

@engine.replay_at_error(err)
wait_for(:alpha)

assert_equal 1, alpha.size
end
end

0 comments on commit 14cbcc7

Please sign in to comment.