feat: migrate webhook execution to background jobs (#1694)

This commit is contained in:
Ephraim Duncan
2025-04-24 06:00:53 +00:00
committed by GitHub
parent 193325717d
commit 6540291055
5 changed files with 122 additions and 63 deletions
@@ -1,6 +1,6 @@
import { jobs } from '../../../jobs/client';
import { verify } from '../../crypto/verify';
import { getAllWebhooksByEventTrigger } from '../get-all-webhooks-by-event-trigger';
import { executeWebhook } from './execute-webhook';
import { ZTriggerWebhookBodySchema } from './schema';
export type HandlerTriggerWebhooksResponse =
@@ -42,17 +42,20 @@ export const handlerTriggerWebhooks = async (req: Request) => {
const allWebhooks = await getAllWebhooksByEventTrigger({ event, userId, teamId });
await Promise.allSettled(
allWebhooks.map(async (webhook) =>
executeWebhook({
event,
webhook,
data,
}),
),
allWebhooks.map(async (webhook) => {
await jobs.triggerJob({
name: 'internal.execute-webhook',
payload: {
event,
webhookId: webhook.id,
data,
},
});
}),
);
return Response.json(
{ success: true, message: 'Webhooks executed successfully' },
{ success: true, message: 'Webhooks queued for execution' },
{ status: 200 },
);
};