feat: unregister webhook upon deleting flow
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import Context from '../../types/express/context';
|
import Context from '../../types/express/context';
|
||||||
import Execution from '../../models/execution';
|
import Execution from '../../models/execution';
|
||||||
import ExecutionStep from '../../models/execution-step';
|
import ExecutionStep from '../../models/execution-step';
|
||||||
|
import globalVariable from '../../helpers/global-variable';
|
||||||
|
import logger from '../../helpers/logger';
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
input: {
|
input: {
|
||||||
@@ -22,6 +24,25 @@ const deleteFlow = async (
|
|||||||
})
|
})
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
|
const triggerStep = await flow.getTriggerStep();
|
||||||
|
const trigger = await triggerStep.getTriggerCommand();
|
||||||
|
|
||||||
|
if (trigger.type === 'webhook' && trigger?.unregisterHook) {
|
||||||
|
const $ = await globalVariable({
|
||||||
|
flow,
|
||||||
|
connection: await triggerStep.$relatedQuery('connection'),
|
||||||
|
app: await triggerStep.getApp(),
|
||||||
|
step: triggerStep,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await trigger.unregisterHook($);
|
||||||
|
} catch (error) {
|
||||||
|
// suppress error as the remote resource might have been already deleted
|
||||||
|
logger.debug(`Failed to unregister webhook for flow ${flow.id}: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const executionIds = (
|
const executionIds = (
|
||||||
await flow.$relatedQuery('executions').select('executions.id')
|
await flow.$relatedQuery('executions').select('executions.id')
|
||||||
).map((execution: Execution) => execution.id);
|
).map((execution: Execution) => execution.id);
|
||||||
|
Reference in New Issue
Block a user