update bindings to support looping
This commit is contained in:
parent
25258ba055
commit
73151722ec
|
@ -98,6 +98,7 @@ const automationActions = store => ({
|
||||||
automationId: automation?._id,
|
automationId: automation?._id,
|
||||||
testData,
|
testData,
|
||||||
})
|
})
|
||||||
|
console.log(result)
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
state.selectedAutomation.testResults = result
|
state.selectedAutomation.testResults = result
|
||||||
return state
|
return state
|
||||||
|
|
|
@ -72,7 +72,9 @@
|
||||||
animate:flip={{ duration: 500 }}
|
animate:flip={{ duration: 500 }}
|
||||||
in:fly|local={{ x: 500, duration: 1500 }}
|
in:fly|local={{ x: 500, duration: 1500 }}
|
||||||
>
|
>
|
||||||
<FlowItem {testDataModal} {block} />
|
{#if block.stepId !== "LOOP"}
|
||||||
|
<FlowItem {testDataModal} {block} />
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
$: testResult = $automationStore.selectedAutomation.testResults?.steps.filter(
|
$: testResult = $automationStore.selectedAutomation.testResults?.steps.filter(
|
||||||
step => (block.id ? step.id === block.id : step.stepId === block.stepId)
|
step => (block.id ? step.id === block.id : step.stepId === block.stepId)
|
||||||
)
|
)
|
||||||
|
$: console.log(testResult)
|
||||||
$: isTrigger = block.type === "TRIGGER"
|
$: isTrigger = block.type === "TRIGGER"
|
||||||
|
|
||||||
$: selected = $automationStore.selectedBlock?.id === block.id
|
$: selected = $automationStore.selectedBlock?.id === block.id
|
||||||
|
@ -51,7 +52,10 @@
|
||||||
block.schema?.inputs?.properties || {}
|
block.schema?.inputs?.properties || {}
|
||||||
).every(x => block?.inputs[x])
|
).every(x => block?.inputs[x])
|
||||||
|
|
||||||
$: loopingSelected = !!block.llop
|
$: loopingSelected =
|
||||||
|
$automationStore.selectedAutomation?.automation.definition.steps.find(
|
||||||
|
x => x.blockToLoop === block.id
|
||||||
|
)
|
||||||
$: showLooping = false
|
$: showLooping = false
|
||||||
async function deleteStep() {
|
async function deleteStep() {
|
||||||
try {
|
try {
|
||||||
|
@ -77,21 +81,18 @@
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
async function removeLooping() {
|
async function removeLooping() {
|
||||||
loopingSelected = false
|
loopingSelected = false
|
||||||
const idx =
|
const loopToDelete =
|
||||||
$automationStore.selectedAutomation.automation.definition.steps.findIndex(
|
$automationStore.selectedAutomation.automation.definition.steps.findIndex(
|
||||||
x => x.id === block.id
|
x => x.blockToLoop === block.id
|
||||||
)
|
)
|
||||||
|
|
||||||
delete $automationStore.selectedAutomation.automation.definition.steps[idx]
|
automationStore.actions.deleteAutomationBlock(loopToDelete)
|
||||||
.loop
|
|
||||||
|
|
||||||
await automationStore.actions.save(
|
await automationStore.actions.save(
|
||||||
$automationStore.selectedAutomation?.automation
|
$automationStore.selectedAutomation?.automation
|
||||||
)
|
)
|
||||||
}*/
|
}
|
||||||
async function addLooping() {
|
async function addLooping() {
|
||||||
loopingSelected = true
|
loopingSelected = true
|
||||||
const loopDefinition = $automationStore.blockDefinitions.ACTION.LOOP
|
const loopDefinition = $automationStore.blockDefinitions.ACTION.LOOP
|
||||||
|
@ -152,18 +153,25 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Divider noMargin />
|
<Divider noMargin />
|
||||||
{#if !showLooping}
|
{#if !showLooping}
|
||||||
<div class="blockSection">
|
<div class="blockSection">
|
||||||
|
<div class="block-options">
|
||||||
|
<div class="delete-padding" on:click={() => deleteStep()}>
|
||||||
|
<Icon name="DeleteOutline" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<Layout noPadding gap="S">
|
<Layout noPadding gap="S">
|
||||||
<AutomationBlockSetup
|
<AutomationBlockSetup
|
||||||
schemaProperties={Object.entries(
|
schemaProperties={Object.entries(
|
||||||
$automationStore.blockDefinitions.ACTION.LOOP.schema.inputs
|
$automationStore.blockDefinitions.ACTION.LOOP.schema.inputs
|
||||||
.properties
|
.properties
|
||||||
)}
|
)}
|
||||||
{block}
|
block={$automationStore.selectedAutomation?.automation.definition.steps.find(
|
||||||
|
x => x.blockToLoop === block.id
|
||||||
|
)}
|
||||||
{webhookModal}
|
{webhookModal}
|
||||||
isLoop={true}
|
|
||||||
/>
|
/>
|
||||||
</Layout>
|
</Layout>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
export let testData
|
export let testData
|
||||||
export let schemaProperties
|
export let schemaProperties
|
||||||
export let isTestModal = false
|
export let isTestModal = false
|
||||||
export let isLoop = false
|
|
||||||
let webhookModal
|
let webhookModal
|
||||||
let drawer
|
let drawer
|
||||||
let tempFilters = lookForFilters(schemaProperties) || []
|
let tempFilters = lookForFilters(schemaProperties) || []
|
||||||
|
@ -74,11 +73,6 @@
|
||||||
await automationStore.actions.save(
|
await automationStore.actions.save(
|
||||||
$automationStore.selectedAutomation?.automation
|
$automationStore.selectedAutomation?.automation
|
||||||
)
|
)
|
||||||
} else if (isLoop) {
|
|
||||||
block.loop[key] = e.detail
|
|
||||||
await automationStore.actions.save(
|
|
||||||
$automationStore.selectedAutomation?.automation
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
block.inputs[key] = e.detail
|
block.inputs[key] = e.detail
|
||||||
await automationStore.actions.save(
|
await automationStore.actions.save(
|
||||||
|
|
|
@ -11,7 +11,7 @@ exports.definition = {
|
||||||
properties: {
|
properties: {
|
||||||
option: {
|
option: {
|
||||||
customType: "loopOption",
|
customType: "loopOption",
|
||||||
title: "Whether it's an array or a string",
|
title: "Input type",
|
||||||
},
|
},
|
||||||
binding: {
|
binding: {
|
||||||
type: "string",
|
type: "string",
|
||||||
|
@ -30,10 +30,18 @@ exports.definition = {
|
||||||
},
|
},
|
||||||
outputs: {
|
outputs: {
|
||||||
properties: {
|
properties: {
|
||||||
currentItem: {
|
items: {
|
||||||
customType: "item",
|
customType: "item",
|
||||||
description: "the item currently being executed",
|
description: "the item currently being executed",
|
||||||
},
|
},
|
||||||
|
success: {
|
||||||
|
type: "boolean",
|
||||||
|
description: "Whether the message sent successfully",
|
||||||
|
},
|
||||||
|
iterations: {
|
||||||
|
type: "number",
|
||||||
|
descriptions: "The amount of times the block ran",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
required: ["success"],
|
required: ["success"],
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,6 +17,7 @@ const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId
|
||||||
const CRON_STEP_ID = triggerDefs.CRON.stepId
|
const CRON_STEP_ID = triggerDefs.CRON.stepId
|
||||||
const STOPPED_STATUS = { success: false, status: "STOPPED" }
|
const STOPPED_STATUS = { success: false, status: "STOPPED" }
|
||||||
const { cloneDeep } = require("lodash/fp")
|
const { cloneDeep } = require("lodash/fp")
|
||||||
|
const { loop } = require("svelte/internal")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The automation orchestrator is a class responsible for executing automations.
|
* The automation orchestrator is a class responsible for executing automations.
|
||||||
|
@ -87,6 +88,7 @@ class Orchestrator {
|
||||||
|
|
||||||
let stepCount = 0
|
let stepCount = 0
|
||||||
let loopStepNumber
|
let loopStepNumber
|
||||||
|
let loopSteps = []
|
||||||
for (let step of automation.definition.steps) {
|
for (let step of automation.definition.steps) {
|
||||||
stepCount++
|
stepCount++
|
||||||
if (step.stepId === LOOP_STEP_ID) {
|
if (step.stepId === LOOP_STEP_ID) {
|
||||||
|
@ -94,10 +96,18 @@ class Orchestrator {
|
||||||
loopStepNumber = stepCount
|
loopStepNumber = stepCount
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
let iterations = loopStep ? loopStep.inputs.binding.split(",").length : 1
|
||||||
|
|
||||||
let iterations = loopStep ? loopStep.inputs.iterations : 1
|
|
||||||
for (let index = 0; index < iterations; index++) {
|
for (let index = 0; index < iterations; index++) {
|
||||||
let originalStepInput = cloneDeep(step.inputs)
|
let originalStepInput = cloneDeep(step.inputs)
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (step.stepId === LOOP_STEP_ID && index >= loopStep.inputs.iterations) {
|
||||||
|
this.executionOutput.steps[loopStepNumber].outputs.status = "Loop Broken"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
// execution stopped, record state for that
|
// execution stopped, record state for that
|
||||||
if (stopped) {
|
if (stopped) {
|
||||||
this.updateExecutionOutput(step.id, step.stepId, {}, STOPPED_STATUS)
|
this.updateExecutionOutput(step.id, step.stepId, {}, STOPPED_STATUS)
|
||||||
|
@ -135,25 +145,56 @@ class Orchestrator {
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// THE OUTPUTS GET SET IN THE CONSTRUCTOR SO WE NEED TO RESET THEM
|
if (loopStep) {
|
||||||
|
loopSteps.push({
|
||||||
this.updateExecutionOutput(step.id, step.stepId, step.inputs, outputs)
|
id: step.id,
|
||||||
|
stepId: step.stepId,
|
||||||
|
inputs: step.inputs,
|
||||||
|
outputs,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.updateExecutionOutput(
|
||||||
|
step.id,
|
||||||
|
step.stepId,
|
||||||
|
step.inputs,
|
||||||
|
outputs
|
||||||
|
)
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Automation error - ${step.stepId} - ${err}`)
|
console.error(`Automation error - ${step.stepId} - ${err}`)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index === iterations - 1) {
|
if (index === iterations - 1) {
|
||||||
loopStep = null
|
loopStep = null
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (loopSteps) {
|
||||||
|
this.executionOutput.steps.splice(loopStepNumber, 0, {
|
||||||
|
id: step.id,
|
||||||
|
stepId: step.stepId,
|
||||||
|
outputs: {
|
||||||
|
success: true,
|
||||||
|
outputs: loopSteps,
|
||||||
|
iterations: iterations,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
this._context.steps.splice(loopStepNumber, 0, {
|
||||||
|
id: step.id,
|
||||||
|
stepId: step.stepId,
|
||||||
|
steps: loopSteps,
|
||||||
|
iterations,
|
||||||
|
success: true,
|
||||||
|
})
|
||||||
|
loopSteps = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Increment quota for automation runs
|
// Increment quota for automation runs
|
||||||
if (!env.SELF_HOSTED && !isDevAppID(this._appId)) {
|
if (!env.SELF_HOSTED && !isDevAppID(this._appId)) {
|
||||||
await usage.update(usage.Properties.AUTOMATION, 1)
|
await usage.update(usage.Properties.AUTOMATION, 1)
|
||||||
}
|
}
|
||||||
// make that we don't loop the next step if we have already been looping (loop block only has one step)
|
// make that we don't loop the next step if we have already been looping (loop block only has one step)
|
||||||
|
|
||||||
return this.executionOutput
|
return this.executionOutput
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue