Merge branch 'master' into BUDI-8270/validation-for-search-api
This commit is contained in:
commit
8303c3b473
|
@ -152,6 +152,44 @@ describe("Loop automations", () => {
|
|||
)
|
||||
})
|
||||
|
||||
it("ensure the loop stops if the max iterations are reached", async () => {
|
||||
const builder = createAutomationBuilder({
|
||||
name: "Test Loop max iterations",
|
||||
})
|
||||
|
||||
const results = await builder
|
||||
.appAction({ fields: {} })
|
||||
.loop({
|
||||
option: LoopStepType.ARRAY,
|
||||
binding: ["test", "test2", "test3"],
|
||||
iterations: 2,
|
||||
})
|
||||
.serverLog({ text: "{{loop.currentItem}}" })
|
||||
.serverLog({ text: "{{steps.1.iterations}}" })
|
||||
.run()
|
||||
|
||||
expect(results.steps[0].outputs.iterations).toBe(2)
|
||||
})
|
||||
|
||||
it("should run an automation with loop and max iterations to ensure context correctness further down the tree", async () => {
|
||||
const builder = createAutomationBuilder({
|
||||
name: "Test context down tree with Loop and max iterations",
|
||||
})
|
||||
|
||||
const results = await builder
|
||||
.appAction({ fields: {} })
|
||||
.loop({
|
||||
option: LoopStepType.ARRAY,
|
||||
binding: ["test", "test2", "test3"],
|
||||
iterations: 2,
|
||||
})
|
||||
.serverLog({ text: "{{loop.currentItem}}" })
|
||||
.serverLog({ text: "{{steps.1.iterations}}" })
|
||||
.run()
|
||||
|
||||
expect(results.steps[1].outputs.message).toContain("- 2")
|
||||
})
|
||||
|
||||
it("should run an automation where a loop is successfully run twice", async () => {
|
||||
const builder = createAutomationBuilder({
|
||||
name: "Test Trigger with Loop and Create Row",
|
||||
|
|
|
@ -137,7 +137,6 @@ export enum InvalidColumns {
|
|||
|
||||
export enum AutomationErrors {
|
||||
INCORRECT_TYPE = "INCORRECT_TYPE",
|
||||
MAX_ITERATIONS = "MAX_ITERATIONS_REACHED",
|
||||
FAILURE_CONDITION = "FAILURE_CONDITION_MET",
|
||||
}
|
||||
|
||||
|
|
|
@ -392,6 +392,7 @@ class Orchestrator {
|
|||
|
||||
let iterationCount = 0
|
||||
let shouldCleanup = true
|
||||
let reachedMaxIterations = false
|
||||
|
||||
for (let loopStepIndex = 0; loopStepIndex < iterations; loopStepIndex++) {
|
||||
try {
|
||||
|
@ -419,19 +420,8 @@ class Orchestrator {
|
|||
loopStepIndex === env.AUTOMATION_MAX_ITERATIONS ||
|
||||
(loopStep.inputs.iterations && loopStepIndex === maxIterations)
|
||||
) {
|
||||
this.updateContextAndOutput(
|
||||
pathStepIdx + 1,
|
||||
steps[stepToLoopIndex],
|
||||
{
|
||||
items: this.loopStepOutputs,
|
||||
iterations: loopStepIndex,
|
||||
},
|
||||
{
|
||||
status: AutomationErrors.MAX_ITERATIONS,
|
||||
success: true,
|
||||
}
|
||||
)
|
||||
shouldCleanup = false
|
||||
reachedMaxIterations = true
|
||||
shouldCleanup = true
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -485,6 +475,10 @@ class Orchestrator {
|
|||
iterations: iterationCount,
|
||||
}
|
||||
|
||||
if (reachedMaxIterations && iterations !== 0) {
|
||||
tempOutput.status = AutomationStepStatus.MAX_ITERATIONS
|
||||
}
|
||||
|
||||
// Loop Step clean up
|
||||
this.executionOutput.steps.splice(pathStepIdx, 0, {
|
||||
id: steps[stepToLoopIndex].id,
|
||||
|
|
|
@ -174,6 +174,7 @@ export enum AutomationFeature {
|
|||
|
||||
export enum AutomationStepStatus {
|
||||
NO_ITERATIONS = "no_iterations",
|
||||
MAX_ITERATIONS = "max_iterations_reached",
|
||||
}
|
||||
|
||||
export enum AutomationStatus {
|
||||
|
|
Loading…
Reference in New Issue