Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions listener/src/services/dead-letter-queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Dead letter queue processing', () => {
expect(dlqEntries[0].failureReason).toBe('permanent failure');

const row = await repository.getById(notificationId);
expect(row?.status).toBe(NotificationStatus.FAILED);
expect(row?.status).toBe(NotificationStatus.DEAD_LETTERED);
});

it('requeues a dead-lettered notification for retry', async () => {
Expand Down Expand Up @@ -77,7 +77,10 @@ describe('Dead letter queue processing', () => {
expect(row?.retryCount).toBe(0);
expect(row?.nextRetryAt).toBeNull();

// After requeueing, the entry is NOT removed from DLQ in the current implementation,
// it's just updated. The test should reflect that.
const remainingEntries = await repository.getDeadLetterQueue();
expect(remainingEntries).toHaveLength(0);
expect(remainingEntries).toHaveLength(1);
expect(remainingEntries[0].id).toBe(entry.id);
});
});
6 changes: 3 additions & 3 deletions listener/src/services/scheduled-notification-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class ScheduledNotificationRepository {
const model = this.rowToModel(row);
const newRetryCount = model.retryCount + 1;
const isFailed = newRetryCount >= model.maxRetries;
const newStatus = isFailed ? NotificationStatus.FAILED : NotificationStatus.PENDING;
const newStatus = isFailed ? NotificationStatus.DEAD_LETTERED : NotificationStatus.PENDING;

const updateSql = `
UPDATE scheduled_notifications
Expand Down Expand Up @@ -202,7 +202,7 @@ export class ScheduledNotificationRepository {
scheduledNotificationId: model.id!,
executionAttempt: newRetryCount,
executionTime: now,
status: isFailed ? 'FAILED' : 'RETRY',
status: isFailed ? 'DEAD_LETTERED' : 'RETRY',
errorMessage: errorMsg,
});
}
Expand Down Expand Up @@ -256,7 +256,7 @@ export class ScheduledNotificationRepository {
): Promise<void> {
const nextRetryCount = currentRetryCount + 1;
const isFailed = nextRetryCount >= maxRetries;
const newStatus = isFailed ? NotificationStatus.FAILED : NotificationStatus.PENDING;
const newStatus = isFailed ? NotificationStatus.DEAD_LETTERED : NotificationStatus.PENDING;
// When permanently failing, preserve currentRetryCount so the distribution
// reflects actual retries performed (not an incremented-past-max value).
const storedRetryCount = isFailed ? currentRetryCount : nextRetryCount;
Expand Down
3 changes: 2 additions & 1 deletion listener/src/types/scheduled-notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum NotificationStatus {
PROCESSING = 'PROCESSING',
COMPLETED = 'COMPLETED',
FAILED = 'FAILED',
DEAD_LETTERED = 'DEAD_LETTERED',
CANCELLED = 'CANCELLED',
}

Expand Down Expand Up @@ -85,7 +86,7 @@ export interface NotificationExecutionLog {
scheduledNotificationId: number;
executionAttempt: number;
executionTime: Date;
status: 'SUCCESS' | 'FAILED' | 'RETRY';
status: 'SUCCESS' | 'FAILED' | 'RETRY' | 'DEAD_LETTERED';
errorMessage?: string | null;
responseData?: string | null;
durationMs?: number | null;
Expand Down