mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
feat(queue): async delivery via Cloudflare Queues with retry backoff and DLQ
This commit is contained in:
parent
737dd7af98
commit
486f38365f
16 changed files with 702 additions and 22 deletions
|
|
@ -11,6 +11,7 @@ import { cfEnv, cfWaitUntil, headersFrom } from "./cf";
|
|||
import { log } from "./lib/log";
|
||||
import { deliveryKey, kvIdempotencyStore } from "./lib/idempotency";
|
||||
import { newCorrelationId } from "./lib/correlation";
|
||||
import { enqueueWebhook, type DeliveryMessage } from "./queue/delivery";
|
||||
|
||||
const MAX_BODY_SIZE = 1024 * 1024;
|
||||
|
||||
|
|
@ -135,6 +136,24 @@ export async function processWebhook(
|
|||
config.routes = config.routes.filter((r) => r.groupId === tenantId);
|
||||
}
|
||||
|
||||
if (env.QUEUE) {
|
||||
const message: DeliveryMessage = {
|
||||
deliveryId: event.deliveryId ?? requestId,
|
||||
groupId: tenantId,
|
||||
provider: provider.id,
|
||||
event: event.event,
|
||||
payload: event.payload,
|
||||
installationId: event.installationId,
|
||||
receivedAt: Date.now(),
|
||||
requestId,
|
||||
};
|
||||
const enqueue = enqueueWebhook(env, message).catch((err) =>
|
||||
log.error({ requestId, err }, "Failed to enqueue webhook"),
|
||||
);
|
||||
waitUntil(enqueue);
|
||||
return { status: 200, body: { ok: true, requestId } };
|
||||
}
|
||||
|
||||
const dispatch = dispatchEvent(config, event, env, groups).catch((err) =>
|
||||
log.error({ requestId, err }, "Dispatch failed"),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue