From 7b7414013655389ae46a3b9819b3c68cc3b471c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Tue, 5 May 2026 13:33:01 -0300 Subject: [PATCH] fix: dispatch webhooks in parallel to prevent blocking and add config logs --- src/controllers/webhook.controller.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/controllers/webhook.controller.ts b/src/controllers/webhook.controller.ts index 522212f..0c00342 100644 --- a/src/controllers/webhook.controller.ts +++ b/src/controllers/webhook.controller.ts @@ -111,22 +111,28 @@ export const handleTinyOrderUpdate = async (req: Request, res: Response): Promis console.log('Forwarding formatted payload to n8n...'); - // 1. Send to the Status Dashboard const statusUrl = process.env.N8N_WEBHOOK_STATUS || process.env.N8N_WEBHOOK_URL; + const graphsUrl = process.env.N8N_WEBHOOK_GRAPHS; + + console.log(`[Config Check] Status URL: ${statusUrl ? 'CONFIGURED' : 'MISSING'}`); + console.log(`[Config Check] Graphs URL: ${graphsUrl ? 'CONFIGURED' : 'MISSING'} (${graphsUrl})`); + + const dispatchPromises: Promise[] = []; + if (statusUrl) { - console.log('-> Sending to Status Workflow...'); - // We don't await here so they send in parallel, or we can await them one by one. - // Awaiting sequentially is safer for error handling. - await sendToN8n(finalPayload, statusUrl); + console.log('-> Preparing dispatch to Status Workflow...'); + dispatchPromises.push(sendToN8n(finalPayload, statusUrl)); } - // 2. Send a copy to the Graphs Dashboard (it will just use the data it needs, like values and dates) - const graphsUrl = process.env.N8N_WEBHOOK_GRAPHS; if (graphsUrl) { - console.log('-> Sending copy to Graphs Workflow...'); - await sendToN8n(finalPayload, graphsUrl); + console.log('-> Preparing dispatch to Graphs Workflow...'); + dispatchPromises.push(sendToN8n(finalPayload, graphsUrl)); } + // Fire them all in parallel so one does not block the other + await Promise.allSettled(dispatchPromises); + console.log('All n8n dispatch attempts completed.'); + } catch (error) { console.error('Error handling Tiny webhook:', error); }