cron automation trigger end to end
This commit is contained in:
parent
025616d7cc
commit
c3dc5bae76
|
@ -61,7 +61,6 @@
|
||||||
|
|
||||||
// Required to check any updated deployment statuses between polls
|
// Required to check any updated deployment statuses between polls
|
||||||
function checkIncomingDeploymentStatus(current, incoming) {
|
function checkIncomingDeploymentStatus(current, incoming) {
|
||||||
console.log(current, incoming)
|
|
||||||
for (let incomingDeployment of incoming) {
|
for (let incomingDeployment of incoming) {
|
||||||
if (
|
if (
|
||||||
incomingDeployment.status === DeploymentStatus.FAILURE ||
|
incomingDeployment.status === DeploymentStatus.FAILURE ||
|
||||||
|
|
|
@ -4,11 +4,6 @@ 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 } = require("../../db/utils")
|
||||||
const { JobQueues } = require("../../constants")
|
|
||||||
const { utils } = require("@budibase/auth/redis")
|
|
||||||
const Queue = env.isTest()
|
|
||||||
? require("../utilities/queue/inMemoryQueue")
|
|
||||||
: require("bull")
|
|
||||||
|
|
||||||
const WH_STEP_ID = triggers.BUILTIN_DEFINITIONS.WEBHOOK.stepId
|
const WH_STEP_ID = triggers.BUILTIN_DEFINITIONS.WEBHOOK.stepId
|
||||||
const CRON_STEP_ID = triggers.BUILTIN_DEFINITIONS.CRON.stepId
|
const CRON_STEP_ID = triggers.BUILTIN_DEFINITIONS.CRON.stepId
|
||||||
|
@ -58,39 +53,21 @@ async function checkForCronTriggers({ appId, oldAuto, newAuto }) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: AUTO GENERATED ID THAT CAN BE USED TO KILL THE CRON JOB ON CHANGE
|
const cronTriggerRemoved =
|
||||||
|
isCronTrigger(oldAuto) && !isCronTrigger(newAuto) && oldTrigger.cronJobId
|
||||||
|
const cronTriggerAdded = !isCronTrigger(oldAuto) && isCronTrigger(newAuto)
|
||||||
|
|
||||||
// need to delete cron trigger
|
if (cronTriggerRemoved) {
|
||||||
if (
|
await triggers.automationQueue.removeRepeatableByKey(oldTrigger.cronJobId)
|
||||||
isCronTrigger(oldAuto) &&
|
|
||||||
!isCronTrigger(newAuto) &&
|
|
||||||
oldTrigger.webhookId
|
|
||||||
) {
|
|
||||||
triggers.automationQueue.add("cron", { repeat: { cron: newAuto.inputs.cron } });
|
|
||||||
// let db = new CouchDB(appId)
|
|
||||||
// // need to get the webhook to get the rev
|
|
||||||
// const webhook = await db.get(oldTrigger.webhookId)
|
|
||||||
// const ctx = {
|
|
||||||
// appId,
|
|
||||||
// params: { id: webhook._id, rev: webhook._rev },
|
|
||||||
// }
|
|
||||||
// // might be updating - reset the inputs to remove the URLs
|
|
||||||
// if (newTrigger) {
|
|
||||||
// delete newTrigger.webhookId
|
|
||||||
// newTrigger.inputs = {}
|
|
||||||
// }
|
|
||||||
// await webhooks.destroy(ctx)
|
|
||||||
}
|
}
|
||||||
// need to create cron job
|
// need to create cron job
|
||||||
else if (!isCronTrigger(oldAuto) && isCronTrigger(newAuto)) {
|
else if (cronTriggerAdded) {
|
||||||
automationQueue.add(newAuto, { repeat: { cron: newAuto.inputs.cron } });
|
const job = await triggers.automationQueue.add(
|
||||||
|
{ automation: newAuto, event: { appId } },
|
||||||
const id = ctx.body.webhook._id
|
{ repeat: { cron: newTrigger.inputs.cron } }
|
||||||
// newTrigger.webhookId = id
|
)
|
||||||
// newTrigger.inputs = {
|
// Assign cron job ID from bull so we can remove it later if the cron trigger is removed
|
||||||
// schemaUrl: `api/webhooks/schema/${appId}/${id}`,
|
newTrigger.cronJobId = job.id
|
||||||
// triggerUrl: `api/webhooks/trigger/${appId}/${id}`,
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
return newAuto
|
return newAuto
|
||||||
}
|
}
|
||||||
|
@ -243,6 +220,10 @@ exports.destroy = async function (ctx) {
|
||||||
appId: ctx.appId,
|
appId: ctx.appId,
|
||||||
oldAuto: oldAutomation,
|
oldAuto: oldAutomation,
|
||||||
})
|
})
|
||||||
|
await checkForCronTriggers({
|
||||||
|
appId: ctx.appId,
|
||||||
|
oldAuto: oldAutomation,
|
||||||
|
})
|
||||||
ctx.body = await db.remove(ctx.params.id, ctx.params.rev)
|
ctx.body = await db.remove(ctx.params.id, ctx.params.rev)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ const FILTER_STEP_ID = logic.BUILTIN_DEFINITIONS.FILTER.stepId
|
||||||
* inputs and handles any outputs.
|
* inputs and handles any outputs.
|
||||||
*/
|
*/
|
||||||
class Orchestrator {
|
class Orchestrator {
|
||||||
constructor(automation, triggerOutput) {
|
constructor(automation, triggerOutput = {}) {
|
||||||
this._metadata = triggerOutput.metadata
|
this._metadata = triggerOutput.metadata
|
||||||
this._chainCount = this._metadata ? this._metadata.automationChainCount : 0
|
this._chainCount = this._metadata ? this._metadata.automationChainCount : 0
|
||||||
this._appId = triggerOutput.appId
|
this._appId = triggerOutput.appId
|
||||||
|
|
|
@ -201,7 +201,7 @@ const BUILTIN_DEFINITIONS = {
|
||||||
name: "Cron Trigger",
|
name: "Cron Trigger",
|
||||||
event: "cron:trigger",
|
event: "cron:trigger",
|
||||||
icon: "ri-timer-line",
|
icon: "ri-timer-line",
|
||||||
tagline: "Cron expression",
|
tagline: "Cron Trigger - {{inputs.cron}}",
|
||||||
description: "Triggers automation on a cron schedule.",
|
description: "Triggers automation on a cron schedule.",
|
||||||
stepId: "CRON",
|
stepId: "CRON",
|
||||||
inputs: {},
|
inputs: {},
|
||||||
|
@ -218,19 +218,10 @@ const BUILTIN_DEFINITIONS = {
|
||||||
},
|
},
|
||||||
outputs: {
|
outputs: {
|
||||||
properties: {
|
properties: {
|
||||||
// row: {
|
body: {
|
||||||
// type: "object",
|
type: "object",
|
||||||
// customType: "row",
|
description: "Body of the request which hit the webhook",
|
||||||
// description: "The row that was updated",
|
},
|
||||||
// },
|
|
||||||
// id: {
|
|
||||||
// type: "string",
|
|
||||||
// description: "Row ID - can be used for updating",
|
|
||||||
// },
|
|
||||||
// revision: {
|
|
||||||
// type: "string",
|
|
||||||
// description: "Revision of row",
|
|
||||||
// },
|
|
||||||
},
|
},
|
||||||
// required: ["row", "id"],
|
// required: ["row", "id"],
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,7 @@ exports.LOGO_URL =
|
||||||
"https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg"
|
"https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg"
|
||||||
|
|
||||||
exports.JobQueues = {
|
exports.JobQueues = {
|
||||||
AUTOMATIONS: "automationQueue"
|
AUTOMATIONS: "automationQueue",
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.FieldTypes = {
|
exports.FieldTypes = {
|
||||||
|
|
Loading…
Reference in New Issue