-
Notifications
You must be signed in to change notification settings - Fork 0
Automated Test: sms-retry-enhanced #380
Closed
+38
−6
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,10 +28,19 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { | |
| //delete all scheduled sms reminders where scheduled date is past current date | ||
| await prisma.workflowReminder.deleteMany({ | ||
| where: { | ||
| method: WorkflowMethods.SMS, | ||
| scheduledDate: { | ||
| lte: dayjs().toISOString(), | ||
| }, | ||
| OR: [ | ||
| { | ||
| method: WorkflowMethods.SMS, | ||
| scheduledDate: { | ||
| lte: dayjs().toISOString(), | ||
| }, | ||
| }, | ||
| { | ||
| retryCount: { | ||
| gt: 1, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
|
|
@@ -44,8 +53,11 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { | |
| lte: dayjs().add(7, "day").toISOString(), | ||
| }, | ||
| }, | ||
| select, | ||
| })) as PartialWorkflowReminder[]; | ||
| select: { | ||
| ...select, | ||
| retryCount: true, | ||
| }, | ||
| })) as (PartialWorkflowReminder & { retryCount: number })[]; | ||
|
|
||
| if (!unscheduledReminders.length) { | ||
| res.json({ ok: true }); | ||
|
|
@@ -163,9 +175,26 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { | |
| referenceId: scheduledSMS.sid, | ||
| }, | ||
| }); | ||
| } else { | ||
| await prisma.workflowReminder.update({ | ||
| where: { | ||
| id: reminder.id, | ||
| }, | ||
| data: { | ||
| retryCount: reminder.retryCount + 1, | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| await prisma.workflowReminder.update({ | ||
| where: { | ||
| id: reminder.id, | ||
| }, | ||
| data: { | ||
| retryCount: reminder.retryCount + 1, | ||
| }, | ||
| }); | ||
| console.log(`Error scheduling SMS with error ${error}`); | ||
|
Comment on lines
189
to
198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The If the Wrap this in a nested try-catch or use 🛡️ Proposed fix } catch (error) {
- await prisma.workflowReminder.update({
- where: {
- id: reminder.id,
- },
- data: {
- retryCount: reminder.retryCount + 1,
- },
- });
+ try {
+ await prisma.workflowReminder.update({
+ where: {
+ id: reminder.id,
+ },
+ data: {
+ retryCount: reminder.retryCount + 1,
+ },
+ });
+ } catch (updateError) {
+ console.log(`Error updating retryCount for reminder ${reminder.id}: ${updateError}`);
+ }
console.log(`Error scheduling SMS with error ${error}`);
}🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
|
||
2 changes: 2 additions & 0 deletions
2
packages/prisma/migrations/20240508134359_add_retry_count_to_workflow_reminder/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "WorkflowReminder" ADD COLUMN "retryCount" INTEGER NOT NULL DEFAULT 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-cal_dot_com-mirror
Length of output: 4246
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-cal_dot_com-mirror
Length of output: 1793
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-cal_dot_com-mirror
Length of output: 262
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-cal_dot_com-mirror
Length of output: 657
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-cal_dot_com-mirror
Length of output: 961
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-cal_dot_com-mirror
Length of output: 917
Add
methodfilter toretryCountdeletion condition to prevent unintended removal of non-SMS reminders.The second
ORbranch deletes anyWorkflowReminderwithretryCount > 1, regardless of method. While currently only the SMS handler incrementsretryCount(keeping email/WhatsApp reminders at 0), this is a logic error that could cause issues if retry logic is added to other methods in the future.Proposed fix
OR: [ { method: WorkflowMethods.SMS, scheduledDate: { lte: dayjs().toISOString(), }, }, { + method: WorkflowMethods.SMS, retryCount: { gt: 1, }, }, ],📝 Committable suggestion
🤖 Prompt for AI Agents