fix: don't schedule reminder from the past (#22353)
* only schedule future reminders * use new Date() instead Co-authored-by: Alex van Andel <me@alexvanandel.com> * use new Date() instead Co-authored-by: Alex van Andel <me@alexvanandel.com> * use new Date() instead Co-authored-by: Alex van Andel <me@alexvanandel.com> --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Alex van Andel <me@alexvanandel.com>
This commit is contained in:
co-authored by
CarinaWolli
Alex van Andel
parent
c472bce54f
commit
9cfc74a74f
@@ -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[];
|
||||
|
||||
@@ -206,8 +206,12 @@ export async function getAllUnscheduledReminders(): Promise<PartialWorkflowRemin
|
||||
method: WorkflowMethods.EMAIL,
|
||||
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
|
||||
},
|
||||
OR: [{ cancelled: false }, { cancelled: null }],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user