feat(webhook): register in mutation calls
This commit is contained in:
@@ -40,27 +40,7 @@ const updateFlowStatus = async (
|
|||||||
pattern: interval || EVERY_15_MINUTES_CRON,
|
pattern: interval || EVERY_15_MINUTES_CRON,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (flow.active) {
|
if (trigger.type === 'webhook') {
|
||||||
// add the flow job in the queue.
|
|
||||||
flow = await flow.$query().patchAndFetch({
|
|
||||||
published_at: new Date().toISOString(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const jobName = `${JOB_NAME}-${flow.id}`;
|
|
||||||
|
|
||||||
await flowQueue.add(
|
|
||||||
jobName,
|
|
||||||
{ flowId: flow.id },
|
|
||||||
{
|
|
||||||
// do not repeat webhook job for immediate webhook registration
|
|
||||||
repeat: trigger.type === 'webhook' ? null : repeatOptions,
|
|
||||||
jobId: flow.id,
|
|
||||||
removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS,
|
|
||||||
removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else if (!flow.active && trigger.type === 'webhook') {
|
|
||||||
// unregister webhook from the application
|
|
||||||
const $ = await globalVariable({
|
const $ = await globalVariable({
|
||||||
flow,
|
flow,
|
||||||
connection: await triggerStep.$relatedQuery('connection'),
|
connection: await triggerStep.$relatedQuery('connection'),
|
||||||
@@ -69,13 +49,35 @@ const updateFlowStatus = async (
|
|||||||
testRun: false,
|
testRun: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
await trigger.unregisterHook($);
|
if (flow.active) {
|
||||||
|
await trigger.registerHook($);
|
||||||
|
} else {
|
||||||
|
await trigger.unregisterHook($);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// remove the job out of the queue
|
if (flow.active) {
|
||||||
const repeatableJobs = await flowQueue.getRepeatableJobs();
|
flow = await flow.$query().patchAndFetch({
|
||||||
const job = repeatableJobs.find((job) => job.id === flow.id);
|
published_at: new Date().toISOString(),
|
||||||
|
});
|
||||||
|
|
||||||
await flowQueue.removeRepeatableByKey(job.key);
|
const jobName = `${JOB_NAME}-${flow.id}`;
|
||||||
|
|
||||||
|
await flowQueue.add(
|
||||||
|
jobName,
|
||||||
|
{ flowId: flow.id },
|
||||||
|
{
|
||||||
|
repeat: repeatOptions,
|
||||||
|
jobId: flow.id,
|
||||||
|
removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS,
|
||||||
|
removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const repeatableJobs = await flowQueue.getRepeatableJobs();
|
||||||
|
const job = repeatableJobs.find((job) => job.id === flow.id);
|
||||||
|
|
||||||
|
await flowQueue.removeRepeatableByKey(job.key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return flow;
|
return flow;
|
||||||
|
@@ -25,8 +25,6 @@ export const processFlow = async (options: ProcessFlowOptions) => {
|
|||||||
try {
|
try {
|
||||||
if (triggerCommand.type === 'webhook' && !flow.active) {
|
if (triggerCommand.type === 'webhook' && !flow.active) {
|
||||||
await triggerCommand.testRun($);
|
await triggerCommand.testRun($);
|
||||||
} else if (triggerCommand.type === 'webhook' && flow.active) {
|
|
||||||
await triggerCommand.registerHook($);
|
|
||||||
} else {
|
} else {
|
||||||
await triggerCommand.run($);
|
await triggerCommand.run($);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user