Skip to content

Commit

Permalink
Handle more dry-run cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hariombalhara committed Dec 20, 2024
1 parent ec920eb commit ab4549d
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/features/bookings/lib/handleConfirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ export async function handleConfirmation(args: {
calendarEvent: evtOfBooking,
isFirstRecurringEvent: isFirstBooking,
hideBranding: !!updatedBookings[index].eventType?.owner?.hideBranding,
isDryRun: false,
});
}
} catch (error) {
Expand Down
17 changes: 15 additions & 2 deletions packages/features/bookings/lib/handleNewBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ async function handler(
responses,
workflows,
rescheduledBy: reqBody.rescheduledBy,
isDryRun,
});

if (newBooking) {
Expand Down Expand Up @@ -1788,6 +1789,7 @@ async function handler(
...webhookData,
paymentId: payment?.id,
},
isDryRun,
});

req.statusCode = 201;
Expand Down Expand Up @@ -1865,13 +1867,23 @@ async function handler(
});

// Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED
await monitorCallbackAsync(handleWebhookTrigger, { subscriberOptions, eventTrigger, webhookData });
await monitorCallbackAsync(handleWebhookTrigger, {
subscriberOptions,
eventTrigger,
webhookData,
isDryRun,
});
} else {
// if eventType requires confirmation we will trigger the BOOKING REQUESTED Webhook
const eventTrigger: WebhookTriggerEvents = WebhookTriggerEvents.BOOKING_REQUESTED;
subscriberOptions.triggerEvent = eventTrigger;
webhookData.status = "PENDING";
await monitorCallbackAsync(handleWebhookTrigger, { subscriberOptions, eventTrigger, webhookData });
await monitorCallbackAsync(handleWebhookTrigger, {
subscriberOptions,
eventTrigger,
webhookData,
isDryRun,
});
}

try {
Expand Down Expand Up @@ -1937,6 +1949,7 @@ async function handler(
isFirstRecurringEvent: req.body.allRecurringDates ? req.body.isFirstRecurringSlot : undefined,
hideBranding: !!eventType.owner?.hideBranding,
seatReferenceUid: evt.attendeeSeatId,
isDryRun,
});
} catch (error) {
loggerWithEventDetails.error("Error while scheduling workflow reminders", JSON.stringify({ error }));
Expand Down
7 changes: 5 additions & 2 deletions packages/features/bookings/lib/handleSeats/handleSeats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ const handleSeats = async (newSeatedBookingObject: NewSeatedBookingObject) => {
evt,
workflows,
rescheduledBy,
isDryRun = false,
} = newSeatedBookingObject;

// TODO: We could allow doing more things to support good dry run for seats
if (isDryRun) return;
const loggerWithEventDetails = createLoggerWithEventDetails(eventType.id, reqBodyUser, eventType.slug);

let resultBooking: HandleSeatsResultBooking = null;
Expand Down Expand Up @@ -124,6 +126,7 @@ const handleSeats = async (newSeatedBookingObject: NewSeatedBookingObject) => {
isFirstRecurringEvent: true,
emailAttendeeSendToOverride: bookerEmail,
seatReferenceUid: evt.attendeeSeatId,
isDryRun,
});
} catch (error) {
loggerWithEventDetails.error("Error while scheduling workflow reminders", JSON.stringify({ error }));
Expand All @@ -149,7 +152,7 @@ const handleSeats = async (newSeatedBookingObject: NewSeatedBookingObject) => {
rescheduledBy,
};

await handleWebhookTrigger({ subscriberOptions, eventTrigger, webhookData });
await handleWebhookTrigger({ subscriberOptions, eventTrigger, webhookData, isDryRun });
}

return resultBooking;
Expand Down
5 changes: 5 additions & 0 deletions packages/features/bookings/lib/handleSeats/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export type NewSeatedBookingObject = {
responses: z.infer<ReturnType<typeof getBookingDataSchema>>["responses"] | null;
rescheduledBy?: string;
workflows: Workflow[];
/**
* It is marked as required field so that it is not accidentally passed as undefined when in dry-run mode
* It could be problematic if that happens, as dry-run is used in automations and can increase the load on the system
*/
isDryRun: boolean;
};

export type RescheduleSeatedBookingObject = NewSeatedBookingObject & { rescheduleUid: string };
Expand Down
8 changes: 8 additions & 0 deletions packages/features/bookings/lib/handleWebhookTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ export async function handleWebhookTrigger(args: {
subscriberOptions: GetSubscriberOptions;
eventTrigger: string;
webhookData: WebhookPayloadType;
/**
* It is marked as required field so that it is not accidentally passed as undefined when in dry-run mode
* It could be problematic if that happens, as dry-run is used in automations and can increase the load on the system
*/
isDryRun: boolean;
}) {
try {
if (args.isDryRun) {
return;
}
const subscribers = await getWebhooks(args.subscriberOptions);

const promises = subscribers.map((sub) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ async function handleWorkflowsUpdate({
bookerUrl,
},
hideBranding: !!eventType?.owner?.hideBranding,
isDryRun: false,
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/features/ee/round-robin/roundRobinReassignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ export const roundRobinReassignment = async ({
bookerUrl,
},
hideBranding: !!eventType?.owner?.hideBranding,
isDryRun: false,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export interface ScheduleWorkflowRemindersArgs extends ProcessWorkflowStepParams
isNotConfirmed?: boolean;
isRescheduleEvent?: boolean;
isFirstRecurringEvent?: boolean;
/**
* It is marked as required field so that it is not accidentally passed as undefined when in dry-run mode
* It could be problematic if that happens, as dry-run is used in automations and can increase the load on the system
*/
isDryRun: boolean;
}

const processWorkflowStep = async (
Expand Down Expand Up @@ -159,7 +164,9 @@ export const scheduleWorkflowReminders = async (args: ScheduleWorkflowRemindersA
emailAttendeeSendToOverride = "",
hideBranding,
seatReferenceUid,
isDryRun = false,
} = args;
if (isDryRun) return;
if (isNotConfirmed || !workflows.length) return;

for (const workflow of workflows) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
status: BookingStatus.REJECTED,
smsReminderNumber: booking.smsReminderNumber || undefined,
};
await handleWebhookTrigger({ subscriberOptions, eventTrigger, webhookData });
await handleWebhookTrigger({ subscriberOptions, eventTrigger, webhookData, isDryRun: false });
}

const message = `Booking ${confirmed}` ? "confirmed" : "rejected";
Expand Down

0 comments on commit ab4549d

Please sign in to comment.