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
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m24s
This commit is contained in:
@@ -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<void>[] = [];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user