🐛 Fix bug that not all webhooks got deleted when active & testing #387

This commit is contained in:
Jan Oberhauser 2020-03-21 00:30:03 +01:00
parent 122a0c79a3
commit e9c6c64290
2 changed files with 12 additions and 16 deletions

View file

@ -1099,16 +1099,7 @@ class App {
// Removes a test webhook // Removes a test webhook
this.app.delete('/rest/test-webhook/:id', ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<boolean> => { this.app.delete('/rest/test-webhook/:id', ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<boolean> => {
const workflowId = req.params.id; const workflowId = req.params.id;
return this.testWebhooks.cancelTestWebhook(workflowId);
const workflowData = await Db.collections.Workflow!.findOne(workflowId);
if (workflowData === undefined) {
throw new ResponseHelper.ResponseError(`Could not find workflow with id "${workflowId}" so webhook could not be deleted!`);
}
const nodeTypes = NodeTypes();
const workflow = new Workflow({ id: workflowId.toString(), name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings });
return this.testWebhooks.cancelTestWebhook(workflowId, workflow);
})); }));

View file

@ -131,7 +131,7 @@ export class TestWebhooks {
// Remove test-webhooks automatically if they do not get called (after 120 seconds) // Remove test-webhooks automatically if they do not get called (after 120 seconds)
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
this.cancelTestWebhook(workflowData.id.toString(), workflow); this.cancelTestWebhook(workflowData.id.toString());
}, 120000); }, 120000);
let key: string; let key: string;
@ -143,10 +143,10 @@ export class TestWebhooks {
workflowData, workflowData,
}; };
await this.activeWebhooks!.add(workflow, webhookData, mode); await this.activeWebhooks!.add(workflow, webhookData, mode);
}
// Save static data! // Save static data!
await WorkflowHelpers.saveStaticData(workflow); this.testWebhookData[key].workflowData.staticData = workflow.staticData;
}
return true; return true;
} }
@ -159,7 +159,9 @@ export class TestWebhooks {
* @returns {boolean} * @returns {boolean}
* @memberof TestWebhooks * @memberof TestWebhooks
*/ */
cancelTestWebhook(workflowId: string, workflow: Workflow): boolean { cancelTestWebhook(workflowId: string): boolean {
const nodeTypes = NodeTypes();
let foundWebhook = false; let foundWebhook = false;
for (const webhookKey of Object.keys(this.testWebhookData)) { for (const webhookKey of Object.keys(this.testWebhookData)) {
const webhookData = this.testWebhookData[webhookKey]; const webhookData = this.testWebhookData[webhookKey];
@ -182,6 +184,9 @@ export class TestWebhooks {
} }
} }
const workflowData = webhookData.workflowData;
const workflow = new Workflow({ id: workflowData.id.toString(), name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings });
// Remove the webhook // Remove the webhook
delete this.testWebhookData[webhookKey]; delete this.testWebhookData[webhookKey];
this.activeWebhooks!.removeWorkflow(workflow); this.activeWebhooks!.removeWorkflow(workflow);
@ -207,7 +212,7 @@ export class TestWebhooks {
for (const webhookKey of Object.keys(this.testWebhookData)) { for (const webhookKey of Object.keys(this.testWebhookData)) {
workflowData = this.testWebhookData[webhookKey].workflowData; workflowData = this.testWebhookData[webhookKey].workflowData;
workflow = new Workflow({ id: workflowData.id.toString(), name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings }); workflow = new Workflow({ id: workflowData.id.toString(), name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings });
workflows.push(); workflows.push(workflow);
} }
return this.activeWebhooks.removeAll(workflows); return this.activeWebhooks.removeAll(workflows);