Updating automations system to return the inputs and outputs of each step.
This commit is contained in:
parent
d2070f9061
commit
b00f8764cb
|
@ -78,8 +78,11 @@ const automationActions = store => ({
|
||||||
},
|
},
|
||||||
trigger: async ({ automation }) => {
|
trigger: async ({ automation }) => {
|
||||||
const { _id } = automation
|
const { _id } = automation
|
||||||
const TRIGGER_AUTOMATION_URL = `/api/automations/${_id}/trigger`
|
return await api.post(`/api/automations/${_id}/trigger`)
|
||||||
return await api.post(TRIGGER_AUTOMATION_URL)
|
},
|
||||||
|
test: async ({ automation }) => {
|
||||||
|
const { _id } = automation
|
||||||
|
return await api.post(`/api/automations/${_id}/test`)
|
||||||
},
|
},
|
||||||
select: automation => {
|
select: automation => {
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testAutomation() {
|
async function testAutomation() {
|
||||||
const result = await automationStore.actions.trigger({
|
const result = await automationStore.actions.test({
|
||||||
automation: $automationStore.selectedAutomation.automation,
|
automation: $automationStore.selectedAutomation.automation,
|
||||||
})
|
})
|
||||||
if (result.status === 200) {
|
if (result.status === 200) {
|
||||||
|
|
|
@ -3,7 +3,12 @@ const actions = require("../../automations/actions")
|
||||||
const logic = require("../../automations/logic")
|
const logic = require("../../automations/logic")
|
||||||
const triggers = require("../../automations/triggers")
|
const triggers = require("../../automations/triggers")
|
||||||
const webhooks = require("./webhook")
|
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 WH_STEP_ID = triggers.TRIGGER_DEFINITIONS.WEBHOOK.stepId
|
||||||
const CRON_STEP_ID = triggers.TRIGGER_DEFINITIONS.CRON.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) {
|
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)
|
let automation = await db.get(ctx.params.id)
|
||||||
await triggers.externalTrigger(automation, {
|
await triggers.externalTrigger(automation, {
|
||||||
...ctx.request.body,
|
...ctx.request.body,
|
||||||
appId: ctx.appId,
|
appId,
|
||||||
})
|
})
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
message: `Automation ${automation._id} has been triggered.`,
|
message: `Automation ${automation._id} has been triggered.`,
|
||||||
|
@ -281,17 +294,18 @@ exports.trigger = async function (ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.test = async function (ctx) {
|
exports.test = async function (ctx) {
|
||||||
const db = new CouchDB(ctx.appId)
|
const appId = ctx.appId
|
||||||
let automation = await db.get(ctx.params.id)
|
if (isProdAppID(appId)) {
|
||||||
ctx.body = {
|
ctx.throw(400, "Cannot test automations in production app.")
|
||||||
automation,
|
|
||||||
responses: await triggers.externalTrigger(
|
|
||||||
automation,
|
|
||||||
{
|
|
||||||
...ctx.request.body,
|
|
||||||
appId: ctx.appId,
|
|
||||||
},
|
|
||||||
{ getResponses: true }
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
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",
|
"/api/automations/:id/trigger",
|
||||||
paramResource("id"),
|
paramResource("id"),
|
||||||
authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE),
|
authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE),
|
||||||
|
controller.trigger
|
||||||
|
)
|
||||||
|
.post(
|
||||||
|
"/api/automations/:id/test",
|
||||||
|
paramResource("id"),
|
||||||
|
authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE),
|
||||||
controller.test
|
controller.test
|
||||||
)
|
)
|
||||||
.delete(
|
.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
|
// create an emitter which has the chain count for this automation run in it, so it can block
|
||||||
// excessive chaining if required
|
// excessive chaining if required
|
||||||
this._emitter = new AutomationEmitter(this._chainCount + 1)
|
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) {
|
async getStepFunctionality(type, stepId) {
|
||||||
|
@ -55,6 +60,15 @@ class Orchestrator {
|
||||||
return this._app
|
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() {
|
async execute() {
|
||||||
let automation = this._automation
|
let automation = this._automation
|
||||||
const app = await this.getApp()
|
const app = await this.getApp()
|
||||||
|
@ -81,12 +95,13 @@ class Orchestrator {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
this._context.steps.push(outputs)
|
this._context.steps.push(outputs)
|
||||||
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this._context
|
return this.executionOutput
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue