SMS workflow reminder retry count tracking#8
Conversation
* add retry count to workflow reminder * add logic to for retry count --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
|
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details: |
|
Claude finished @ShashankFC's task in 1m 55s —— View job Code ReviewTasks
OverviewThis PR adds retry count tracking to SMS workflow reminders to prevent infinite retry attempts when SMS sending fails. The implementation adds a Issues Found1. Critical: Hardcoded retry limit with magic numberLocation: {
retryCount: {
gt: 1,
},
}The retry limit is hardcoded as
Recommendation: Extract to a named constant with documentation: const MAX_SMS_RETRY_COUNT = 1; // Maximum number of retry attempts before giving up
// In the delete query:
{
retryCount: {
gt: MAX_SMS_RETRY_COUNT,
},
}2. Bug: Overly aggressive deletion logicLocation: The deletion logic has a significant flaw: await prisma.workflowReminder.deleteMany({
where: {
OR: [
{
method: WorkflowMethods.SMS,
scheduledDate: {
lte: dayjs().toISOString(),
},
},
{
retryCount: {
gt: 1,
},
},
],
},
});Problem: The Impact: This could unintentionally delete email and WhatsApp workflow reminders that have failed multiple times, even though retry tracking might not be implemented for those methods yet. Recommendation: Apply the SMS method filter to both conditions: await prisma.workflowReminder.deleteMany({
where: {
method: WorkflowMethods.SMS,
OR: [
{
scheduledDate: {
lte: dayjs().toISOString(),
},
},
{
retryCount: {
gt: MAX_SMS_RETRY_COUNT,
},
},
],
},
});3. Code Quality: Duplicate database update logicLocation: The same retry count increment logic appears in two places: // When scheduleSMS returns falsy (line 178-186)
await prisma.workflowReminder.update({
where: { id: reminder.id },
data: { retryCount: reminder.retryCount + 1 },
});
// In catch block (line 190-198)
await prisma.workflowReminder.update({
where: { id: reminder.id },
data: { retryCount: reminder.retryCount + 1 },
});Recommendation: Extract to a helper function to maintain DRY principle: async function incrementRetryCount(reminderId: number, currentCount: number) {
await prisma.workflowReminder.update({
where: { id: reminderId },
data: { retryCount: currentCount + 1 },
});
}
// Usage:
} else {
await incrementRetryCount(reminder.id, reminder.retryCount);
}
// In catch:
await incrementRetryCount(reminder.id, reminder.retryCount);4. Missing: Error logging contextLocation: console.log(`Error scheduling SMS with error ${error}`);The error log doesn't include important context like:
Recommendation: Enhance error logging: console.error(
`Error scheduling SMS reminder (attempt ${reminder.retryCount + 1}/${MAX_SMS_RETRY_COUNT + 1}):`,
{
reminderId: reminder.id,
bookingUid: reminder.booking?.uid,
scheduledDate: reminder.scheduledDate,
error: error instanceof Error ? error.message : String(error),
}
);5. Missing: Observability for retry exhaustionWhen a reminder reaches the retry limit and gets deleted, there's no logging or tracking. This makes it difficult to:
Recommendation: Add logging before deletion or track exhausted reminders separately: // Option 1: Log before deletion
const exhaustedReminders = await prisma.workflowReminder.findMany({
where: {
method: WorkflowMethods.SMS,
retryCount: { gt: MAX_SMS_RETRY_COUNT }
},
select: { id: true, bookingUid: true }
});
if (exhaustedReminders.length > 0) {
console.warn(`Deleting ${exhaustedReminders.length} exhausted SMS reminders:`,
exhaustedReminders.map(r => r.bookingUid));
}6. PR Title IssueThe PR title "SMS workflow reminder retry count tracking" doesn't follow Conventional Commits specification. It should have a prefix like:
Based on the implementation, this appears to be a bug fix for infinite retry attempts, so the title should be: Positive Observations✅ Database migration properly includes default value - The SummaryThe PR successfully implements retry tracking for SMS reminders, but has some important issues:
I recommend addressing issues #1 and #2 before merging, as they could lead to unexpected behavior in production. |
|
This PR is being marked as stale due to inactivity. |
Test 9nn---nReplicated from ai-code-review-evaluation/cal.com-greptile#9