44require_relative 'example_helper'
55
66class DelayedAction < Dynflow ::Action
7- def plan
8- plan_self
7+ def plan ( should_fail = false )
8+ plan_self :should_fail => should_fail
99 end
1010
1111 def run
1212 sleep 5
13+ raise "Controlled failure" if input [ :should_fail ]
14+ end
15+
16+ def rescue_strategy
17+ Dynflow ::Action ::Rescue ::Fail
1318 end
1419end
1520
1621if $PROGRAM_NAME == __FILE__
17- ExampleHelper . world . action_logger . level = 1
18- ExampleHelper . world . logger . level = 0
22+ world = ExampleHelper . create_world do |config |
23+ config . auto_rescue = true
24+ end
25+ world . action_logger . level = 1
26+ world . logger . level = 0
1927
20- plan1 = ExampleHelper . world . trigger ( DelayedAction )
21- plan2 = ExampleHelper . world . chain ( plan1 . execution_plan_id , DelayedAction )
22- plan3 = ExampleHelper . world . chain ( plan2 . execution_plan_id , DelayedAction )
23- plan4 = ExampleHelper . world . chain ( plan2 . execution_plan_id , DelayedAction )
28+ plan1 = world . trigger ( DelayedAction )
29+ plan2 = world . chain ( plan1 . execution_plan_id , DelayedAction )
30+ plan3 = world . chain ( plan2 . execution_plan_id , DelayedAction )
31+ plan4 = world . chain ( plan2 . execution_plan_id , DelayedAction )
32+
33+ plan5 = world . trigger ( DelayedAction , true )
34+ plan6 = world . chain ( plan5 . execution_plan_id , DelayedAction )
2435
2536 puts <<-MSG . gsub ( /^.*\| / , '' )
2637 |
@@ -34,9 +45,12 @@ def run
3445 | #{ plan2 . id } is delayed and should run once #{ plan1 . id } finishes.
3546 | #{ plan3 . id } and #{ plan4 . id } are delayed and should run once #{ plan2 . id } finishes.
3647 |
48+ | #{ plan5 . id } runs immediately and is expected to fail.
49+ | #{ plan6 . id } should not run at all as its prerequisite failed.
50+ |
3751 | Visit #{ ExampleHelper ::DYNFLOW_URL } to see their status.
3852 |
3953 MSG
4054
41- ExampleHelper . run_web_console
55+ ExampleHelper . run_web_console ( world )
4256end
0 commit comments