From ce39be403c2c6efc372eb96d6729cbb3600315b3 Mon Sep 17 00:00:00 2001 From: Charles d'Avernas Date: Fri, 6 Dec 2024 13:33:07 +0100 Subject: [PATCH] fix(Runner): Fixed the `ForTaskExecutor`, which was not properly running when the list to enumerate contained only 1 item Signed-off-by: Charles d'Avernas --- .../Services/Executors/ForTaskExecutor.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/runner/Synapse.Runner/Services/Executors/ForTaskExecutor.cs b/src/runner/Synapse.Runner/Services/Executors/ForTaskExecutor.cs index f07b1add5..994a04889 100644 --- a/src/runner/Synapse.Runner/Services/Executors/ForTaskExecutor.cs +++ b/src/runner/Synapse.Runner/Services/Executors/ForTaskExecutor.cs @@ -68,11 +68,15 @@ protected override async Task DoExecuteAsync(CancellationToken cancellationToken { if (this.Collection == null) throw new InvalidOperationException("The executor must be initialized before execution"); var task = await this.Task.GetSubTasksAsync(cancellationToken).OrderBy(t => t.CreatedAt).LastOrDefaultAsync(cancellationToken).ConfigureAwait(false); - var index = task == null ? 0 : int.Parse(task.Reference.OriginalString.Split('/', StringSplitOptions.RemoveEmptyEntries).Last()); - if (index == this.Collection.Count - 1) + var index = 0; + if (task != null) { - await this.SetResultAsync(this.Task.Input, this.Task.Definition.Then, cancellationToken).ConfigureAwait(false); - return; + index = int.Parse(task.Reference.OriginalString.Split('/', StringSplitOptions.RemoveEmptyEntries).Last()); + if (index == this.Collection.Count - 1) + { + await this.SetResultAsync(this.Task.Input, this.Task.Definition.Then, cancellationToken).ConfigureAwait(false); + return; + } } var item = this.Collection.ElementAt(index); var taskDefinition = new DoTaskDefinition()