@@ -40,7 +40,7 @@ public void InitializeFlowRunner(in string path)
4040 var flowJson = JToken . ReadFrom ( jsonTextReader ) ;
4141 var flowDefinition = flowJson . SelectToken ( "$.*.definition" ) ;
4242 _trigger = flowDefinition . SelectToken ( "$.triggers" ) . First as JProperty ;
43- _scopeManager . Push ( "root" , flowDefinition . SelectToken ( "$.actions" ) . OfType < JProperty > ( ) ) ;
43+ _scopeManager . Push ( "root" , flowDefinition . SelectToken ( "$.actions" ) . OfType < JProperty > ( ) , null ) ;
4444 }
4545
4646 public async Task < object > Trigger ( ValueContainer triggerOutputs )
@@ -56,7 +56,7 @@ public async Task Trigger()
5656 {
5757 var trigger = GetActionExecutor ( _trigger ) ;
5858
59- trigger . InitializeActionExecutor ( _trigger . Name , _trigger . Value ) ;
59+ trigger . InitializeActionExecutor ( _trigger . Name , _trigger . Value ) ;
6060 await trigger . Execute ( ) ;
6161
6262 await RunFlow ( ) ;
@@ -72,9 +72,8 @@ private async Task RunFlow()
7272 if ( _flowRunnerSettings . IgnoreActions . Contains ( currentAd . Name ) )
7373 {
7474 currentAd = _scopeManager . CurrentActionDescriptions . FirstOrDefault ( a =>
75- a . Value . SelectToken ( "$.runAfter" ) . First ? . ToObject < JProperty > ( ) . Name ==
76- currentAd . Name &&
77- a . Value . SelectToken ( "$.runAfter.*" ) . Values ( ) . Any (
75+ a . Value . SelectToken ( "$.runAfter" ) . First ? . ToObject < JProperty > ( ) . Name == currentAd . Name
76+ && a . Value . SelectToken ( "$.runAfter.*" ) . Values ( ) . Any (
7877 x => x ? . Value < string > ( ) == ActionStatus . Succeeded . ToString ( ) ) ) ;
7978 continue ;
8079 }
@@ -87,30 +86,43 @@ private async Task RunFlow()
8786 break ;
8887 }
8988
89+ // If an action failes inside a scope, and a suitable action isn't found inside the given scope, that
90+ // actions status is transferred to be the scope status. This isn't the case atm
91+
92+ // TODO: Figure out how to get actionResult from
9093 var actionDescName = currentAd . Name ;
91- while ( ! DetermineNextAction ( actionResult , out currentAd , actionDescName ) )
94+ var nextAction = actionResult . NextAction ;
95+ var actionResultStatus = actionResult . ActionStatus ;
96+ while ( ! DetermineNextAction ( nextAction , actionResultStatus , out currentAd , actionDescName ) )
9297 {
93- if ( ! _scopeManager . TryPopScope ( out actionDescName ) )
98+ nextAction = null ;
99+ var t = await _scopeManager . TryPopScope ( actionResultStatus ) ;
100+ if ( t == null )
94101 {
102+ currentAd = null ;
95103 break ;
96104 }
105+
106+ actionResultStatus = t . ActionStatus ;
107+ actionDescName = t . NextAction ;
97108 }
98109 }
99110 }
100111
101- private bool DetermineNextAction ( ActionResult actionResult , out JProperty currentActionDesc , string adName )
112+ private bool DetermineNextAction ( string nextAction , ActionStatus actionResultStatus ,
113+ out JProperty currentActionDesc , string adName )
102114 {
103- if ( actionResult ? . NextAction == null )
115+ if ( nextAction == null )
104116 {
105117 currentActionDesc = _scopeManager . CurrentActionDescriptions . FirstOrDefault ( a =>
106118 a . Value . SelectToken ( "$.runAfter" ) . First ? . ToObject < JProperty > ( ) . Name == adName &&
107119 a . Value . SelectToken ( "$.runAfter.*" ) . Values ( ) . Any (
108- x => x ? . Value < string > ( ) == actionResult ? . ActionStatus . ToString ( ) ) ) ;
120+ x => x ? . Value < string > ( ) == actionResultStatus . ToString ( ) ) ) ;
109121 }
110122 else
111123 {
112124 currentActionDesc =
113- _scopeManager . CurrentActionDescriptions . First ( a => a . Name == actionResult . NextAction ) ;
125+ _scopeManager . CurrentActionDescriptions . First ( a => a . Name == nextAction ) ;
114126 }
115127
116128 return currentActionDesc != null ;
@@ -121,7 +133,7 @@ private static async Task<ActionResult> ExecuteAction(ActionExecutorBase actionE
121133 {
122134 if ( actionExecutor == null ) return null ;
123135
124- actionExecutor . InitializeActionExecutor ( currentAction . Name , currentAction . First ) ;
136+ actionExecutor . InitializeActionExecutor ( currentAction . Name , currentAction . First ) ;
125137 return await actionExecutor . Execute ( ) ;
126138 }
127139
0 commit comments