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 () => {
|
it("should run an automation where a loop is successfully run twice", async () => {
|
||||||
const builder = createAutomationBuilder({
|
const builder = createAutomationBuilder({
|
||||||
name: "Test Trigger with Loop and Create Row",
|
name: "Test Trigger with Loop and Create Row",
|
||||||
|
|
|
@ -137,7 +137,6 @@ export enum InvalidColumns {
|
||||||
|
|
||||||
export enum AutomationErrors {
|
export enum AutomationErrors {
|
||||||
INCORRECT_TYPE = "INCORRECT_TYPE",
|
INCORRECT_TYPE = "INCORRECT_TYPE",
|
||||||
MAX_ITERATIONS = "MAX_ITERATIONS_REACHED",
|
|
||||||
FAILURE_CONDITION = "FAILURE_CONDITION_MET",
|
FAILURE_CONDITION = "FAILURE_CONDITION_MET",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -392,6 +392,7 @@ class Orchestrator {
|
||||||
|
|
||||||
let iterationCount = 0
|
let iterationCount = 0
|
||||||
let shouldCleanup = true
|
let shouldCleanup = true
|
||||||
|
let reachedMaxIterations = false
|
||||||
|
|
||||||
for (let loopStepIndex = 0; loopStepIndex < iterations; loopStepIndex++) {
|
for (let loopStepIndex = 0; loopStepIndex < iterations; loopStepIndex++) {
|
||||||
try {
|
try {
|
||||||
|
@ -419,19 +420,8 @@ class Orchestrator {
|
||||||
loopStepIndex === env.AUTOMATION_MAX_ITERATIONS ||
|
loopStepIndex === env.AUTOMATION_MAX_ITERATIONS ||
|
||||||
(loopStep.inputs.iterations && loopStepIndex === maxIterations)
|
(loopStep.inputs.iterations && loopStepIndex === maxIterations)
|
||||||
) {
|
) {
|
||||||
this.updateContextAndOutput(
|
reachedMaxIterations = true
|
||||||
pathStepIdx + 1,
|
shouldCleanup = true
|
||||||
steps[stepToLoopIndex],
|
|
||||||
{
|
|
||||||
items: this.loopStepOutputs,
|
|
||||||
iterations: loopStepIndex,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: AutomationErrors.MAX_ITERATIONS,
|
|
||||||
success: true,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
shouldCleanup = false
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,6 +475,10 @@ class Orchestrator {
|
||||||
iterations: iterationCount,
|
iterations: iterationCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (reachedMaxIterations && iterations !== 0) {
|
||||||
|
tempOutput.status = AutomationStepStatus.MAX_ITERATIONS
|
||||||
|
}
|
||||||
|
|
||||||
// Loop Step clean up
|
// Loop Step clean up
|
||||||
this.executionOutput.steps.splice(pathStepIdx, 0, {
|
this.executionOutput.steps.splice(pathStepIdx, 0, {
|
||||||
id: steps[stepToLoopIndex].id,
|
id: steps[stepToLoopIndex].id,
|
||||||
|
|
|
@ -174,6 +174,7 @@ export enum AutomationFeature {
|
||||||
|
|
||||||
export enum AutomationStepStatus {
|
export enum AutomationStepStatus {
|
||||||
NO_ITERATIONS = "no_iterations",
|
NO_ITERATIONS = "no_iterations",
|
||||||
|
MAX_ITERATIONS = "max_iterations_reached",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AutomationStatus {
|
export enum AutomationStatus {
|
||||||
|
|
Loading…
Reference in New Issue