From 0a567a3302b7151df252a50dfd88fd241d07c99b Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Fri, 31 Mar 2023 12:20:47 +0100 Subject: [PATCH] add new status to handle no iterations during loop --- .../AutomationBuilder/TestDisplay.svelte | 2 +- packages/server/src/threads/automation.ts | 20 +++++++++++++++---- .../types/src/documents/app/automation.ts | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/TestDisplay.svelte b/packages/builder/src/components/automation/AutomationBuilder/TestDisplay.svelte index 043844b6d2..aa441cec40 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/TestDisplay.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/TestDisplay.svelte @@ -58,7 +58,7 @@ /> {#if openBlocks[block.id]} - {#if filteredResults?.[idx]?.outputs.iterations} + {#if filteredResults?.[idx]?.outputs?.iterations}
diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 74c202c33d..c19b05a8a7 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -34,8 +34,8 @@ const STOPPED_STATUS = { success: true, status: AutomationStatus.STOPPED } function getLoopIterations(loopStep: LoopStep, input: LoopInput) { const binding = automationUtils.typecastForLooping(loopStep, input) - if (!loopStep || !binding) { - return 1 + if (!binding) { + return 0 } if (Array.isArray(binding)) { return binding.length @@ -43,7 +43,7 @@ function getLoopIterations(loopStep: LoopStep, input: LoopInput) { if (typeof binding === "string") { return automationUtils.stringSplit(binding).length } - return 1 + return 0 } /** @@ -423,13 +423,25 @@ class Orchestrator { } } + if (loopStep && iterations === 0) { + loopStep = undefined + this.executionOutput.steps.splice(loopStepNumber + 1, 0, { + id: step.id, + stepId: step.stepId, + outputs: { status: AutomationStatus.NO_ITERATIONS, success: true }, + inputs: {}, + }) + + this._context.steps.splice(loopStepNumber, 1) + iterations = 1 + } + // Delete the step after the loop step as it's irrelevant, since information is included // in the loop step if (wasLoopStep && !loopStep) { this._context.steps.splice(loopStepNumber + 1, 1) wasLoopStep = false } - if (loopSteps && loopSteps.length) { let tempOutput = { success: true, diff --git a/packages/types/src/documents/app/automation.ts b/packages/types/src/documents/app/automation.ts index 0aa11d808b..0c431b1f93 100644 --- a/packages/types/src/documents/app/automation.ts +++ b/packages/types/src/documents/app/automation.ts @@ -83,6 +83,7 @@ export enum AutomationStatus { ERROR = "error", STOPPED = "stopped", STOPPED_ERROR = "stopped_error", + NO_ITERATIONS = "no_iterations", } export interface AutomationResults {