Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cancel workflows on cancel booking #17871

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions packages/features/ee/workflows/api/scheduleEmailReminders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@ import { SchedulingType, WorkflowActions, WorkflowMethods, WorkflowTemplates } f
import { bookingMetadataSchema } from "@calcom/prisma/zod-utils";

import type { PartialWorkflowReminder } from "../lib/getWorkflowReminders";
import {
getAllRemindersToCancel,
getAllRemindersToDelete,
getAllUnscheduledReminders,
} from "../lib/getWorkflowReminders";
import { getAllRemindersToCancel, getAllUnscheduledReminders } from "../lib/getWorkflowReminders";
import {
cancelScheduledEmail,
deleteScheduledSend,
getBatchId,
sendSendgridMail,
} from "../lib/reminders/providers/sendgridProvider";
Expand All @@ -43,24 +38,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
return;
}

// delete batch_ids with already past scheduled date from scheduled_sends
const remindersToDelete: { referenceId: string | null }[] = await getAllRemindersToDelete();

const deletePromises: Promise<any>[] = [];

for (const reminder of remindersToDelete) {
const deletePromise = deleteScheduledSend(reminder.referenceId);
deletePromises.push(deletePromise);
}

Promise.allSettled(deletePromises).then((results) => {
results.forEach((result) => {
if (result.status === "rejected") {
logger.error(`Error deleting batch id from scheduled_sends: ${result.reason}`);
}
});
});

//delete workflow reminders with past scheduled date
await prisma.workflowReminder.deleteMany({
where: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { bookingMetadataSchema } from "@calcom/prisma/zod-utils";

import { getBatchId, sendSendgridMail } from "./providers/sendgridProvider";
import { cancelScheduledEmail as cancelScheduledEmailSend } from "./providers/sendgridProvider";
import type { AttendeeInBookingInfo, BookingInfo, timeUnitLowerCase } from "./smsReminderManager";
import type { VariablesType } from "./templates/customTemplate";
import customTemplate from "./templates/customTemplate";
Expand Down Expand Up @@ -377,6 +378,8 @@ export const deleteScheduledEmailReminder = async (reminderId: number, reference
cancelled: true,
},
});

await cancelScheduledEmailSend(referenceId);
} catch (error) {
log.error(`Error canceling reminder with error ${error}`);
}
Expand Down
Loading