chore: Infrastructure scaffolding for Webhook's Producer/Consumer approach before wiring (#25954)

* --INIT

* fixes

* better comments and some clean up

* test and type fix

* clean up

* address feedback

* fix erroneous booking_confirmed to booking_rescheduled
This commit is contained in:
Syed Ali Shahbaz authored and GitHub committed 2026-01-22 18:33:34 +05:30
1 parent a63bf11c3f
commit c4c62369e5
35 files changed
+2124 -91

No files matched your search

+4 -2
View File
@@ -1,7 +1,6 @@
import type { z } from "zod";
import type { FORM_SUBMITTED_WEBHOOK_RESPONSES } from "@calcom/app-store/routing-forms/lib/formSubmissionUtils";
import type { BookingAuditTaskConsumerPayload } from "@calcom/features/booking-audit/lib/types/bookingAuditTask";
import type { z } from "zod";
export type TaskerTypes = "internal" | "redis";
type TaskPayloads = {
@@ -43,6 +42,9 @@ type TaskPayloads = {
sendAwaitingPaymentEmail: z.infer<
typeof import("./tasks/sendAwaitingPaymentEmail").sendAwaitingPaymentEmailPayloadSchema
>;
webhookDelivery: z.infer<
typeof import("@calcom/features/webhooks/lib/types/webhookTask").webhookTaskPayloadSchema
>;
};
export type TaskTypes = keyof TaskPayloads;
export type TaskHandler = (payload: string, taskId?: string) => Promise<void>;
+5
View File
@@ -34,6 +34,7 @@ const tasks: Record<TaskTypes, () => Promise<TaskHandler>> = {
sendAwaitingPaymentEmail: () =>
import("./sendAwaitingPaymentEmail").then((module) => module.sendAwaitingPaymentEmail),
bookingAudit: () => import("./bookingAudit").then((module) => module.bookingAudit),
webhookDelivery: () => import("./webhookDelivery").then((module) => module.webhookDelivery),
};
export const tasksConfig = {
@@ -44,5 +45,9 @@ export const tasksConfig = {
executeAIPhoneCall: {
maxAttempts: 1,
},
webhookDelivery: {
minRetryIntervalMins: IS_PRODUCTION ? 5 : 1,
maxAttempts: 3,
},
};
export default tasks;
@@ -0,0 +1,39 @@
import { getWebhookTaskConsumer } from "@calcom/features/di/webhooks/containers/webhook";
import { webhookTaskPayloadSchema } from "@calcom/features/webhooks/lib/types/webhookTask";
import logger from "@calcom/lib/logger";
/**
* Webhook Delivery Task Handler
*
* This task is queued by WebhookTaskerProducerService and processed here.
* It delegates to WebhookTaskConsumer (via DI) which handles the heavy lifting:
* - Fetching webhook subscribers
* - Fetching event-specific data from database
* - Building versioned webhook payloads
* - Sending HTTP requests to subscriber URLs
*
* This handler can be deployed to trigger.dev for scalability.
*/
const log = logger.getSubLogger({ prefix: ["webhookDelivery"] });
export async function webhookDelivery(payload: string, taskId?: string): Promise<void> {
try {
if (!taskId) {
log.error("Task ID is required for webhook delivery consumer", {
taskId,
});
throw new Error("Task ID is required for webhook delivery consumer");
}
const parsedPayload = webhookTaskPayloadSchema.parse(JSON.parse(payload));
const consumer = getWebhookTaskConsumer();
await consumer.processWebhookTask(parsedPayload, taskId);
} catch (error) {
log.error("Failed to process webhook delivery task", {
taskId,
error: error instanceof Error ? error.message : String(error),
});
throw error;
}
}