fix: don't schedule reminder from the past (#22353)

* only schedule future reminders

* use new Date() instead

Co-authored-by: Alex van Andel <[email protected]>

* use new Date() instead

Co-authored-by: Alex van Andel <[email protected]>

* use new Date() instead

Co-authored-by: Alex van Andel <[email protected]>

---------

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-07-17 14:33:56 +00:00
1 parent c472bce54f
commit 9cfc74a74f
3 files changed
+9 -10

No files matched your search

@@ -35,6 +35,7 @@ export async function handler(req: NextRequest) {
method: WorkflowMethods.SMS,
scheduled: false,
scheduledDate: {
gte: new Date(),
lte: dayjs().add(2, "hour").toISOString(),
},
retryCount: {
@@ -24,24 +24,18 @@ export async function handler(req: NextRequest) {
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
}
//delete all scheduled whatsapp reminders where scheduled date is past current date
await prisma.workflowReminder.deleteMany({
where: {
method: WorkflowMethods.WHATSAPP,
scheduledDate: {
lte: dayjs().toISOString(),
},
},
});
//find all unscheduled WHATSAPP reminders
const unscheduledReminders = (await prisma.workflowReminder.findMany({
where: {
method: WorkflowMethods.WHATSAPP,
scheduled: false,
scheduledDate: {
gte: new Date(),
lte: dayjs().add(2, "hour").toISOString(),
},
retryCount: {
lt: 3, // Don't continue retrying if it's already failed 3 times
},
},
select,
})) as PartialWorkflowReminder[];