mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
feat(queue): async delivery via Cloudflare Queues with retry backoff and DLQ
This commit is contained in:
16 files changed
+702
-22
No files matched your search
@@ -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"),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user