feat: configure BullMQ retry strategy and dead letter handling#580
Open
chrispaskvan wants to merge 5 commits into
Open
feat: configure BullMQ retry strategy and dead letter handling#580chrispaskvan wants to merge 5 commits into
chrispaskvan wants to merge 5 commits into
Conversation
Add retry configuration, error classification, and job lifecycle management for notification jobs to prevent permanent notification loss from transient failures. - Add defaultJobOptions to Queue: 3 attempts with exponential backoff (5s, 10s, 20s), completed job cleanup (24h), failed job retention (7d) - Refactor #send() error handling to classify errors as transient (retry via BullMQ), permanent (UnrecoverableError), or business-logic (XurUnavailableError sends fallback SMS) - Emit Application Insights metric on retry exhaustion - Enhance subscriber failed-event logging with attempt counts Closes #569 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR configures BullMQ retries/cleanup for notification jobs and refactors notification sending so transient failures can actually trigger BullMQ retries, while business-logic “Xur unavailable” failures still send a fallback message.
Changes:
- Configure BullMQ
QueuedefaultJobOptions(attempts/backoff, remove-on-complete/fail retention) and add a “retries exhausted” metric emission on failed events. - Refactor
NotificationController.#send()error handling to rethrow transient errors (retry), mark permanent errors asUnrecoverableError(no retry), and introduceXurUnavailableErrorfor business-logic fallback. - Expand unit tests around retry/permanent/fallback behavior and job exhaustion metric behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| notifications/xur-unavailable.error.js | Adds a dedicated business-logic error type for Xur inventory unavailability. |
| notifications/notification.controller.js | Implements transient/permanent/business-logic error classification for Xur notifications. |
| notifications/notification.controller.spec.js | Adds test coverage for transient rethrow, permanent unrecoverable failures, and business-logic fallback. |
| helpers/publisher.js | Adds BullMQ default retry/cleanup options and emits an App Insights metric when retries are exhausted. |
| helpers/publisher.spec.js | Tests queue configuration and the exhausted-retries metric emission logic. |
| helpers/subscriber.js | Enhances worker failed logging with attempt counts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add ClaimCheck.updatePhoneNumber in XurUnavailableError fallback path - Wrap publisher failed handler in try/catch with defensive opts access - Preserve original error as cause on UnrecoverableError, guard re-wrapping - Narrow getXur error handling: only DestinyError becomes XurUnavailableError Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… cause - Only convert DestinyError with status 'DestinyVendorNotFound' to XurUnavailableError; rethrow other DestinyErrors for outer handling - Preserve original error as cause on XurUnavailableError - Fix DestinyError constructor arg order in tests (code, message, status) - Add test for non-VendorNotFound DestinyError becoming UnrecoverableError Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix resolves.not.toThrow() assertions to use resolves.toBeUndefined() - Use fallback of 1 (BullMQ default) instead of Infinity for missing opts.attempts - Update test expectation for missing opts to reflect new fallback behavior Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes two compounding bugs that cause permanent notification loss from transient failures:
defaultJobOptions, defaulting to 1 attempt (0 retries). The worker re-threw errors but retries never fired.#send()caught every exception and sent a fallback SMS, so jobs always appeared successful to BullMQ — even if retries were configured, they'd never trigger.Changes
defaultJobOptionsto Queue: 3 attempts with exponential backoff (5s, 10s, 20s), completed job cleanup (24h/1000 max), failed job retention (7d/500 max)#send()error handling to classify errors:UnrecoverableError(no retries)XurUnavailableError→ send fallback SMS, job succeedsnotification-job-exhausted) when retries are exhaustedfailedevent logging with attempt countsXurUnavailableErrorclass for Xur business-logic errorsTest plan
defaultJobOptionsshape, metric emission on exhaustion, no metric when retries remainUnrecoverableError, only business-logic getXur failures trigger fallback SMSCloses #569
🤖 Generated with Claude Code