Skip to content

Commit 2dae0bf

Browse files
CarinaWolliCarinaWolliUdit-takkar
authored
fix: add retryCount to workflowReminder (#14943)
* add retry count to workflow reminder * add logic to for retry count --------- Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
1 parent 917c7b0 commit 2dae0bf

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

packages/features/ee/workflows/api/scheduleSMSReminders.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
2828
//delete all scheduled sms reminders where scheduled date is past current date
2929
await prisma.workflowReminder.deleteMany({
3030
where: {
31-
method: WorkflowMethods.SMS,
32-
scheduledDate: {
33-
lte: dayjs().toISOString(),
34-
},
31+
OR: [
32+
{
33+
method: WorkflowMethods.SMS,
34+
scheduledDate: {
35+
lte: dayjs().toISOString(),
36+
},
37+
},
38+
{
39+
retryCount: {
40+
gt: 1,
41+
},
42+
},
43+
],
3544
},
3645
});
3746

@@ -44,8 +53,11 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
4453
lte: dayjs().add(7, "day").toISOString(),
4554
},
4655
},
47-
select,
48-
})) as PartialWorkflowReminder[];
56+
select: {
57+
...select,
58+
retryCount: true,
59+
},
60+
})) as (PartialWorkflowReminder & { retryCount: number })[];
4961

5062
if (!unscheduledReminders.length) {
5163
res.json({ ok: true });
@@ -163,9 +175,26 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
163175
referenceId: scheduledSMS.sid,
164176
},
165177
});
178+
} else {
179+
await prisma.workflowReminder.update({
180+
where: {
181+
id: reminder.id,
182+
},
183+
data: {
184+
retryCount: reminder.retryCount + 1,
185+
},
186+
});
166187
}
167188
}
168189
} catch (error) {
190+
await prisma.workflowReminder.update({
191+
where: {
192+
id: reminder.id,
193+
},
194+
data: {
195+
retryCount: reminder.retryCount + 1,
196+
},
197+
});
169198
console.log(`Error scheduling SMS with error ${error}`);
170199
}
171200
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "WorkflowReminder" ADD COLUMN "retryCount" INTEGER NOT NULL DEFAULT 0;

packages/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ model WorkflowReminder {
997997
cancelled Boolean?
998998
seatReferenceId String?
999999
isMandatoryReminder Boolean? @default(false)
1000+
retryCount Int @default(0)
10001001
10011002
@@index([bookingUid])
10021003
@@index([workflowStepId])

0 commit comments

Comments
 (0)