improve context handling

This commit is contained in:
Peter Clement 2022-03-25 10:52:22 +00:00
parent 7817d65eb3
commit 25258ba055
1 changed files with 5 additions and 11 deletions

View File

@ -16,6 +16,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")
/** /**
* The automation orchestrator is a class responsible for executing automations. * The automation orchestrator is a class responsible for executing automations.
@ -96,6 +97,7 @@ class Orchestrator {
let iterations = loopStep ? loopStep.inputs.iterations : 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)
// 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)
@ -108,22 +110,15 @@ class Orchestrator {
currentItem: loopStep.inputs.binding.split(",")[index], currentItem: loopStep.inputs.binding.split(",")[index],
} }
} }
let stepFn = await this.getStepFunctionality(step.stepId) let stepFn = await this.getStepFunctionality(step.stepId)
console.log(step.inputs) let inputs = await processObject(originalStepInput, this._context)
inputs = automationUtils.cleanInputValues(inputs, step.schema.inputs)
step.inputs = await processObject(step.inputs, this._context)
step.inputs = automationUtils.cleanInputValues(
step.inputs,
step.schema.inputs
)
console.log(step.inputs)
try { try {
// appId is always passed // appId is always passed
let tenantId = app.tenantId || DEFAULT_TENANT_ID let tenantId = app.tenantId || DEFAULT_TENANT_ID
const outputs = await doInTenant(tenantId, () => { const outputs = await doInTenant(tenantId, () => {
return stepFn({ return stepFn({
inputs: step.inputs, inputs: inputs,
appId: this._appId, appId: this._appId,
emitter: this._emitter, emitter: this._emitter,
context: this._context, context: this._context,
@ -143,7 +138,6 @@ class Orchestrator {
// THE OUTPUTS GET SET IN THE CONSTRUCTOR SO WE NEED TO RESET THEM // THE OUTPUTS GET SET IN THE CONSTRUCTOR SO WE NEED TO RESET THEM
this.updateExecutionOutput(step.id, step.stepId, step.inputs, outputs) this.updateExecutionOutput(step.id, step.stepId, step.inputs, outputs)
console.log(this.executionOutput.input)
} catch (err) { } catch (err) {
console.error(`Automation error - ${step.stepId} - ${err}`) console.error(`Automation error - ${step.stepId} - ${err}`)
return err return err