fix: dispatch webhooks in parallel to prevent blocking and add config logs
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m24s

This commit is contained in:
Cauê Faleiros
2026-05-05 13:33:01 -03:00
parent ff2f5aca29
commit 7b74140136

View File

@@ -111,22 +111,28 @@ export const handleTinyOrderUpdate = async (req: Request, res: Response): Promis
console.log('Forwarding formatted payload to n8n...'); 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 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<void>[] = [];
if (statusUrl) { if (statusUrl) {
console.log('-> Sending to Status Workflow...'); console.log('-> Preparing dispatch to Status Workflow...');
// We don't await here so they send in parallel, or we can await them one by one. dispatchPromises.push(sendToN8n(finalPayload, statusUrl));
// Awaiting sequentially is safer for error handling.
await 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) { if (graphsUrl) {
console.log('-> Sending copy to Graphs Workflow...'); console.log('-> Preparing dispatch to Graphs Workflow...');
await sendToN8n(finalPayload, graphsUrl); 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) { } catch (error) {
console.error('Error handling Tiny webhook:', error); console.error('Error handling Tiny webhook:', error);
} }