Updating automations system to return the inputs and outputs of each step.
This commit is contained in:
parent
213bee1e3b
commit
e84d30524b
|
@ -78,8 +78,11 @@ const automationActions = store => ({
|
|||
},
|
||||
trigger: async ({ automation }) => {
|
||||
const { _id } = automation
|
||||
const TRIGGER_AUTOMATION_URL = `/api/automations/${_id}/trigger`
|
||||
return await api.post(TRIGGER_AUTOMATION_URL)
|
||||
return await api.post(`/api/automations/${_id}/trigger`)
|
||||
},
|
||||
test: async ({ automation }) => {
|
||||
const { _id } = automation
|
||||
return await api.post(`/api/automations/${_id}/test`)
|
||||
},
|
||||
select: automation => {
|
||||
store.update(state => {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
}
|
||||
|
||||
async function testAutomation() {
|
||||
const result = await automationStore.actions.trigger({
|
||||
const result = await automationStore.actions.test({
|
||||
automation: $automationStore.selectedAutomation.automation,
|
||||
})
|
||||
if (result.status === 200) {
|
||||
|
|
|
@ -3,7 +3,12 @@ const actions = require("../../automations/actions")
|
|||
const logic = require("../../automations/logic")
|
||||
const triggers = require("../../automations/triggers")
|
||||
const webhooks = require("./webhook")
|
||||
const { getAutomationParams, generateAutomationID } = require("../../db/utils")
|
||||
const {
|
||||
getAutomationParams,
|
||||
generateAutomationID,
|
||||
isDevAppID,
|
||||
isProdAppID,
|
||||
} = require("../../db/utils")
|
||||
|
||||
const WH_STEP_ID = triggers.TRIGGER_DEFINITIONS.WEBHOOK.stepId
|
||||
const CRON_STEP_ID = triggers.TRIGGER_DEFINITIONS.CRON.stepId
|
||||
|
@ -268,11 +273,19 @@ module.exports.getDefinitionList = async function (ctx) {
|
|||
*********************/
|
||||
|
||||
exports.trigger = async function (ctx) {
|
||||
const db = new CouchDB(ctx.appId)
|
||||
const appId = ctx.appId
|
||||
if (isDevAppID(appId)) {
|
||||
// in dev apps don't throw an error, just don't trigger
|
||||
ctx.body = {
|
||||
message: "Automation not triggered, app in development.",
|
||||
}
|
||||
return
|
||||
}
|
||||
const db = new CouchDB(appId)
|
||||
let automation = await db.get(ctx.params.id)
|
||||
await triggers.externalTrigger(automation, {
|
||||
...ctx.request.body,
|
||||
appId: ctx.appId,
|
||||
appId,
|
||||
})
|
||||
ctx.body = {
|
||||
message: `Automation ${automation._id} has been triggered.`,
|
||||
|
@ -281,17 +294,18 @@ exports.trigger = async function (ctx) {
|
|||
}
|
||||
|
||||
exports.test = async function (ctx) {
|
||||
const db = new CouchDB(ctx.appId)
|
||||
let automation = await db.get(ctx.params.id)
|
||||
ctx.body = {
|
||||
automation,
|
||||
responses: await triggers.externalTrigger(
|
||||
automation,
|
||||
{
|
||||
...ctx.request.body,
|
||||
appId: ctx.appId,
|
||||
},
|
||||
{ getResponses: true }
|
||||
),
|
||||
const appId = ctx.appId
|
||||
if (isProdAppID(appId)) {
|
||||
ctx.throw(400, "Cannot test automations in production app.")
|
||||
}
|
||||
const db = new CouchDB(appId)
|
||||
let automation = await db.get(ctx.params.id)
|
||||
ctx.body = await triggers.externalTrigger(
|
||||
automation,
|
||||
{
|
||||
...ctx.request.body,
|
||||
appId,
|
||||
},
|
||||
{ getResponses: true }
|
||||
)
|
||||
}
|
||||
|
|
|
@ -88,6 +88,12 @@ router
|
|||
"/api/automations/:id/trigger",
|
||||
paramResource("id"),
|
||||
authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE),
|
||||
controller.trigger
|
||||
)
|
||||
.post(
|
||||
"/api/automations/:id/test",
|
||||
paramResource("id"),
|
||||
authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE),
|
||||
controller.test
|
||||
)
|
||||
.delete(
|
||||
|
|
|
@ -30,6 +30,11 @@ class Orchestrator {
|
|||
// create an emitter which has the chain count for this automation run in it, so it can block
|
||||
// excessive chaining if required
|
||||
this._emitter = new AutomationEmitter(this._chainCount + 1)
|
||||
this.executionOutput = { trigger: {}, steps: [] }
|
||||
// setup the execution output
|
||||
const triggerStepId = automation.definition.trigger.stepId
|
||||
const triggerId = automation.definition.trigger.id
|
||||
this.updateExecutionOutput(triggerId, triggerStepId, null, triggerOutput)
|
||||
}
|
||||
|
||||
async getStepFunctionality(type, stepId) {
|
||||
|
@ -55,6 +60,15 @@ class Orchestrator {
|
|||
return this._app
|
||||
}
|
||||
|
||||
updateExecutionOutput(id, stepId, inputs, outputs) {
|
||||
const stepObj = { id, stepId, inputs, outputs }
|
||||
// first entry is always the trigger (constructor)
|
||||
if (this.executionOutput.steps.length === 0) {
|
||||
this.executionOutput.trigger = stepObj
|
||||
}
|
||||
this.executionOutput.steps.push(stepObj)
|
||||
}
|
||||
|
||||
async execute() {
|
||||
let automation = this._automation
|
||||
const app = await this.getApp()
|
||||
|
@ -81,12 +95,13 @@ class Orchestrator {
|
|||
break
|
||||
}
|
||||
this._context.steps.push(outputs)
|
||||
this.updateExecutionOutput(step.id, step.stepId, step.inputs, outputs)
|
||||
} catch (err) {
|
||||
console.error(`Automation error - ${step.stepId} - ${err}`)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return this._context
|
||||
return this.executionOutput
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue