Fixing an issue where any workflow would be triggered by the same type of event - now matching models.
This commit is contained in:
parent
53bbcd9928
commit
cba125256a
|
@ -8,4 +8,5 @@ module.exports = {
|
||||||
SALT_ROUNDS: process.env.SALT_ROUNDS,
|
SALT_ROUNDS: process.env.SALT_ROUNDS,
|
||||||
LOGGER: process.env.LOGGER,
|
LOGGER: process.env.LOGGER,
|
||||||
BUDIBASE_ENVIRONMENT: process.env.BUDIBASE_ENVIRONMENT,
|
BUDIBASE_ENVIRONMENT: process.env.BUDIBASE_ENVIRONMENT,
|
||||||
|
SENDGRID_API_KEY: process.env.SENDGRID_API_KEY,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
const environment = require("../../environment")
|
||||||
const sgMail = require("@sendgrid/mail")
|
const sgMail = require("@sendgrid/mail")
|
||||||
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
|
sgMail.setApiKey(environment.SENDGRID_API_KEY)
|
||||||
|
|
||||||
module.exports.definition = {
|
module.exports.definition = {
|
||||||
description: "Send an email",
|
description: "Send an email",
|
||||||
|
@ -52,7 +53,7 @@ module.exports.run = async function({ inputs }) {
|
||||||
to: inputs.to,
|
to: inputs.to,
|
||||||
from: inputs.from,
|
from: inputs.from,
|
||||||
subject: inputs.subject,
|
subject: inputs.subject,
|
||||||
text: inputs.text,
|
text: inputs.text ? inputs.text : "Empty",
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -76,7 +76,7 @@ const BUILTIN_DEFINITIONS = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
async function queueRelevantWorkflows(event, eventType) {
|
async function queueRelevantRecordWorkflows(event, eventType) {
|
||||||
if (event.instanceId == null) {
|
if (event.instanceId == null) {
|
||||||
throw `No instanceId specified for ${eventType} - check event emitters.`
|
throw `No instanceId specified for ${eventType} - check event emitters.`
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,13 @@ async function queueRelevantWorkflows(event, eventType) {
|
||||||
|
|
||||||
const workflows = workflowsToTrigger.rows.map(wf => wf.doc)
|
const workflows = workflowsToTrigger.rows.map(wf => wf.doc)
|
||||||
for (let workflow of workflows) {
|
for (let workflow of workflows) {
|
||||||
if (!workflow.live) {
|
let workflowDef = workflow.definition
|
||||||
|
let workflowTrigger = workflowDef ? workflowDef.trigger : {}
|
||||||
|
if (
|
||||||
|
!workflow.live ||
|
||||||
|
!workflowTrigger.inputs ||
|
||||||
|
workflowTrigger.inputs.modelId !== event.record.modelId
|
||||||
|
) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
workflowQueue.add({ workflow, event })
|
workflowQueue.add({ workflow, event })
|
||||||
|
@ -96,11 +102,17 @@ async function queueRelevantWorkflows(event, eventType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
emitter.on("record:save", async function(event) {
|
emitter.on("record:save", async function(event) {
|
||||||
await queueRelevantWorkflows(event, "record:save")
|
if (!event || !event.record || !event.record.modelId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await queueRelevantRecordWorkflows(event, "record:save")
|
||||||
})
|
})
|
||||||
|
|
||||||
emitter.on("record:delete", async function(event) {
|
emitter.on("record:delete", async function(event) {
|
||||||
await queueRelevantWorkflows(event, "record:delete")
|
if (!event || !event.record || !event.record.modelId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await queueRelevantRecordWorkflows(event, "record:delete")
|
||||||
})
|
})
|
||||||
|
|
||||||
async function fillRecordOutput(workflow, params) {
|
async function fillRecordOutput(workflow, params) {
|
||||||
|
|
Loading…
Reference in New Issue