@@ -169,28 +169,9 @@ func Visit(workflow *Workflow, taskId TaskId, excludeEnd bool) []Task {
169169 return tasks
170170}
171171
172- func (workflow * Workflow ) doNothingExec (progress * Progress , input * PartialData , task UnaryTask , r * Request ) (* PartialData , * Progress , bool , error ) {
173-
174- output := input .Data
175- outputData := NewPartialData (ReqId (r .Id ), task .GetNext (), output )
176-
177- progress .Complete (task .GetId ())
178-
179- shouldContinueExecution := task .GetType () != Fail && task .GetType () != Succeed
180- if shouldContinueExecution {
181- err := progress .AddReadyTask (task .GetNext ())
182- if err != nil {
183- return nil , progress , false , nil
184- }
185- }
186-
187- return outputData , progress , shouldContinueExecution , nil
188- }
189-
190172func (workflow * Workflow ) Execute (r * Request , input * PartialData , progress * Progress ) (* PartialData , * Progress , bool , error ) {
191- var output * PartialData
192173 var err error
193- shouldContinue := true
174+ var outputData * PartialData
194175
195176 var nextTasks []TaskId
196177
@@ -213,24 +194,57 @@ func (workflow *Workflow) Execute(r *Request, input *PartialData, progress *Prog
213194 }
214195
215196 switch task := n .(type ) {
216- case * FunctionTask :
217- output , progress , shouldContinue , err = task .execute (progress , input , r )
218- case * ChoiceTask :
219- output , progress , shouldContinue , err = task .execute (progress , input , r )
220- case * StartTask :
221- output , progress , shouldContinue , err = task .execute (progress , input )
222- case * PassTask :
223- output , progress , shouldContinue , err = workflow .doNothingExec (progress , input , task , r )
224- case * FailureTask :
225- output , progress , shouldContinue , err = task .execute (progress , r )
226- case * SuccessTask :
227- output , progress , shouldContinue , err = workflow .doNothingExec (progress , input , task , r )
197+ case UnaryTask :
198+ output , err := task .execute (input , r )
199+ if err != nil {
200+ progress .Fail (n .GetId ())
201+ return nil , progress , false , err
202+ }
203+ progress .Complete (task .GetId ())
204+
205+ nextTask := task .GetNext ()
206+ outputData = NewPartialData (ReqId (r .Id ), nextTask , output )
207+ if progress .IsReady (nextTask ) {
208+ progress .ReadyToExecute = append (progress .ReadyToExecute , nextTask )
209+ }
210+
211+ case ConditionalTask :
212+ nextTaskId , err := task .Evaluate (input , r )
213+ if err != nil {
214+ progress .Fail (n .GetId ())
215+ return nil , progress , false , err
216+ }
217+
218+ // we skip all tasks that will not be executed
219+ toSkip := make ([]Task , 0 )
220+ toNotSkip := Visit (workflow , nextTaskId , false )
221+ for _ , a := range task .GetAlternatives () {
222+ if a == nextTaskId {
223+ continue
224+ }
225+ branchTasks := Visit (workflow , a , false )
226+ for _ , otherTask := range branchTasks {
227+ if ! slices .Contains (toNotSkip , otherTask ) {
228+ toSkip = append (toSkip , otherTask )
229+ }
230+ }
231+ }
232+ for _ , t := range toSkip {
233+ progress .Skip (t .GetId ())
234+ }
235+ progress .Complete (task .GetId ())
236+
237+ outputData = NewPartialData (ReqId (r .Id ), nextTaskId , input .Data )
238+ if progress .IsReady (nextTaskId ) {
239+ progress .ReadyToExecute = append (progress .ReadyToExecute , nextTaskId )
240+ }
228241 case * EndTask :
229- output , progress , shouldContinue , err = task .execute (progress , input )
242+ progress .Complete (task .GetId ())
243+ outputData = input
230244 }
231245 if err != nil {
232246 progress .Fail (n .GetId ())
233- return output , progress , false , err
247+ return nil , progress , false , err
234248 }
235249 } else {
236250 err = SaveProgress (progress )
@@ -244,7 +258,7 @@ func (workflow *Workflow) Execute(r *Request, input *PartialData, progress *Prog
244258 return nil , progress , false , nil
245259 }
246260
247- return output , progress , shouldContinue , nil
261+ return outputData , progress , true , nil
248262}
249263
250264// GetUniqueFunctions returns a list with the function names used in the Workflow. The returned function names are unique and in alphabetical order
@@ -440,7 +454,7 @@ func (workflow *Workflow) Invoke(r *Request) error {
440454 return fmt .Errorf ("failed workflow execution: %v" , err )
441455 }
442456
443- if ! shouldContinue && pd != nil {
457+ if len ( progress . ReadyToExecute ) == 0 && pd != nil {
444458 r .ExecReport .Result = pd .Data
445459 }
446460 }
0 commit comments