1
0
Fork 0
mirror of synced 2024-09-10 22:46:09 +12:00

more parsing of output bindings

This commit is contained in:
Peter Clement 2022-03-29 10:29:51 +01:00
parent 73151722ec
commit 006bf368bb
5 changed files with 37 additions and 40 deletions

View file

@ -98,7 +98,6 @@ const automationActions = store => ({
automationId: automation?._id,
testData,
})
console.log(result)
store.update(state => {
state.selectedAutomation.testResults = result
return state

View file

@ -34,7 +34,6 @@
$: testResult = $automationStore.selectedAutomation.testResults?.steps.filter(
step => (block.id ? step.id === block.id : step.stepId === block.stepId)
)
$: console.log(testResult)
$: isTrigger = block.type === "TRIGGER"
$: selected = $automationStore.selectedBlock?.id === block.id
@ -57,6 +56,7 @@
x => x.blockToLoop === block.id
)
$: showLooping = false
async function deleteStep() {
try {
automationStore.actions.deleteAutomationBlock(block)
@ -81,18 +81,6 @@
)
}
async function removeLooping() {
loopingSelected = false
const loopToDelete =
$automationStore.selectedAutomation.automation.definition.steps.findIndex(
x => x.blockToLoop === block.id
)
automationStore.actions.deleteAutomationBlock(loopToDelete)
await automationStore.actions.save(
$automationStore.selectedAutomation?.automation
)
}
async function addLooping() {
loopingSelected = true
const loopDefinition = $automationStore.blockDefinitions.ACTION.LOOP
@ -103,6 +91,7 @@
loopDefinition
)
loopBlock.blockToLoop = block.id
block.loopBlock = loopBlock.id
automationStore.actions.addBlockToAutomation(loopBlock, blockIdx - 1)
await automationStore.actions.save(
$automationStore.selectedAutomation?.automation
@ -142,6 +131,16 @@
</div>
<div class="blockTitle">
{#if testResult && testResult[0]}
<div style="float: right;" on:click={() => resultsModal.show()}>
<StatusLight
positive={isTrigger || testResult[0].outputs?.success}
negative={!testResult[0].outputs?.success}
><Body size="XS">View response</Body></StatusLight
>
</div>
{/if}
<div
style="margin-left: 10px;"
on:click={() => {

View file

@ -104,7 +104,13 @@
)
bindings = bindings.concat(
outputs.map(([name, value]) => {
const runtime = idx === 0 ? `trigger.${name}` : `steps.${idx}.${name}`
let runtimeName =
$automationStore.selectedAutomation.automation.definition.steps.find(
x => block.id === x.blockToLoop
)
? `loop.${name}`
: `steps.${idx}.${name}`
const runtime = idx === 0 ? `trigger.${name}` : runtimeName
return {
label: runtime,
type: value.type,
@ -115,6 +121,7 @@
})
)
}
return bindings
}

View file

@ -36,7 +36,7 @@ exports.definition = {
},
success: {
type: "boolean",
description: "Whether the message sent successfully",
description: "Whether the message loop was successfully",
},
iterations: {
type: "number",

View file

@ -17,7 +17,6 @@ const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId
const CRON_STEP_ID = triggerDefs.CRON.stepId
const STOPPED_STATUS = { success: false, status: "STOPPED" }
const { cloneDeep } = require("lodash/fp")
const { loop } = require("svelte/internal")
/**
* The automation orchestrator is a class responsible for executing automations.
@ -89,6 +88,7 @@ class Orchestrator {
let stepCount = 0
let loopStepNumber
let loopSteps = []
let lastLoopStep
for (let step of automation.definition.steps) {
stepCount++
if (step.stepId === LOOP_STEP_ID) {
@ -145,13 +145,9 @@ class Orchestrator {
})
continue
}
if (loopStep) {
loopSteps.push({
id: step.id,
stepId: step.stepId,
inputs: step.inputs,
outputs,
})
this._context.steps.splice(loopStepNumber, 1)
if (loopStep && loopSteps) {
loopSteps.push(outputs)
} else {
this.updateExecutionOutput(
step.id,
@ -166,34 +162,30 @@ class Orchestrator {
}
if (index === iterations - 1) {
lastLoopStep = loopStep
loopStep = null
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,
if (loopSteps && loopSteps.length) {
let tempOutput = { success: true, outputs: loopSteps }
this.executionOutput.steps.splice(loopStep, 0, {
id: lastLoopStep.id,
stepId: lastLoopStep.stepId,
outputs: tempOutput,
inputs: step.inputs,
})
this._context.steps.splice(loopStep, 0, tempOutput)
loopSteps = null
}
}
// Increment quota for automation runs
if (!env.SELF_HOSTED && !isDevAppID(this._appId)) {
await usage.update(usage.Properties.AUTOMATION, 1)
}
console.log(JSON.stringify(this._context, null, 2))
// make that we don't loop the next step if we have already been looping (loop block only has one step)
return this.executionOutput
}