feat(job-queue): resilient background job retry & monitoring (#130)#380
Open
macan88 wants to merge 3 commits intorohitdash08:mainfrom
Open
feat(job-queue): resilient background job retry & monitoring (#130)#380macan88 wants to merge 3 commits intorohitdash08:mainfrom
macan88 wants to merge 3 commits intorohitdash08:mainfrom
Conversation
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.
Problem
Async API calls (dashboard, analytics, expenses) had no retry logic or observability, meaning transient network errors or 5xx responses caused immediate user-facing failures with no recovery path.
Solution
Added
JobQueueandJobMonitorclasses inapp/src/lib/jobQueue.tsthat wrap any async function with configurable exponential backoff retry (default: 3 attempts, 200 ms base delay) and lifecycle hooks (onSuccess,onRetry,onFailure,onDead). The retry policy explicitly distinguishes transient (5xx / network) from permanent (4xx) errors — permanent errors short-circuit immediately to avoid wasting retries. Jobs that exhaust all retries are placed in a dead-letter state for operator inspection without losing error context.Testing
app/src/__tests__/jobQueue.test.tswith three focused cases:maxAttempts, resolves on successonFailureonceonDeadfireddefaultRetryPolicy.isRetryableunit-tested for 4xx vs 5xx/network patternsjest.useFakeTimers()so backoff delays do not slow CIDocumentation
docs/job-queue.mdcovering API, retry policy customisation, dead-letter inspection, and memory management guidance.Closes #130