feat(webhook): register in mutation calls
This commit is contained in:
@@ -40,8 +40,22 @@ const updateFlowStatus = async (
|
||||
pattern: interval || EVERY_15_MINUTES_CRON,
|
||||
};
|
||||
|
||||
if (trigger.type === 'webhook') {
|
||||
const $ = await globalVariable({
|
||||
flow,
|
||||
connection: await triggerStep.$relatedQuery('connection'),
|
||||
app: await triggerStep.getApp(),
|
||||
step: triggerStep,
|
||||
testRun: false,
|
||||
});
|
||||
|
||||
if (flow.active) {
|
||||
await trigger.registerHook($);
|
||||
} else {
|
||||
await trigger.unregisterHook($);
|
||||
}
|
||||
} else {
|
||||
if (flow.active) {
|
||||
// add the flow job in the queue.
|
||||
flow = await flow.$query().patchAndFetch({
|
||||
published_at: new Date().toISOString(),
|
||||
});
|
||||
@@ -52,31 +66,19 @@ const updateFlowStatus = async (
|
||||
jobName,
|
||||
{ flowId: flow.id },
|
||||
{
|
||||
// do not repeat webhook job for immediate webhook registration
|
||||
repeat: trigger.type === 'webhook' ? null : repeatOptions,
|
||||
repeat: 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({
|
||||
flow,
|
||||
connection: await triggerStep.$relatedQuery('connection'),
|
||||
app: await triggerStep.getApp(),
|
||||
step: triggerStep,
|
||||
testRun: false,
|
||||
});
|
||||
|
||||
await trigger.unregisterHook($);
|
||||
} else {
|
||||
// remove the job out of the queue
|
||||
const repeatableJobs = await flowQueue.getRepeatableJobs();
|
||||
const job = repeatableJobs.find((job) => job.id === flow.id);
|
||||
|
||||
await flowQueue.removeRepeatableByKey(job.key);
|
||||
}
|
||||
}
|
||||
|
||||
return flow;
|
||||
};
|
||||
|
@@ -25,8 +25,6 @@ export const processFlow = async (options: ProcessFlowOptions) => {
|
||||
try {
|
||||
if (triggerCommand.type === 'webhook' && !flow.active) {
|
||||
await triggerCommand.testRun($);
|
||||
} else if (triggerCommand.type === 'webhook' && flow.active) {
|
||||
await triggerCommand.registerHook($);
|
||||
} else {
|
||||
await triggerCommand.run($);
|
||||
}
|
||||
|
Reference in New Issue
Block a user