Feature/accounting sync retry#1151
Open
TheDEV111 wants to merge 3 commits into
Open
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.
Closes #975
PR Description: QuickBooks/Xero Failed Operations Retry Queue
Overview
This pull request implements Issue #975 [MEDIUM]: Create Retry Queue for Failed QuickBooks/Xero Operations. It introduces a robust, resilient retry mechanism utilizing BullMQ with exponential backoff to handle transient network issues or API rate-limit errors (HTTP 429) when syncing transaction data to external accounting platforms (QuickBooks Online and Xero).
Additionally, it isolates permanent errors (e.g., payload validation mismatches) from transient ones to immediately halt and discard failed transactions, preventing queue pollution and wasteful API calls.
Architectural Implementation
1. Mock Services with Error Classification
src/services/accounting/accountingService.tsRateLimitError(HTTP 429),NetworkError(Timeout/Outage).ValidationError(Invalid amount, missing reference numbers, incorrect parameters).setMockFailures) for robust unit testing in Jest.2. BullMQ Queue Configurations
src/queue/syncQueue.tsaccounting-syncqueue underbullmq.attempts: 5(max retry attempts).delay: 3000(initial delay of 3 seconds, scaling exponentially to 6s, 12s, 24s, 48s).3. Queue Processor / Worker
src/queue/syncWorker.tsawait job.discard(), and immediately throws to finalize the failure without further retries.4. Admin Routing & Stats APIs
src/routes/accounting.tsPOST /api/accounting/sync: Enqueues sync operations with auto-generated uniquesyncId.GET /api/accounting/sync/stats: Returns wait times, active jobs, completed, and failed counts.GET /api/accounting/sync/:jobId: Returns status, history, retry attempts, and specific error reports.src/index.ts/api/accountingprotected by token authentication.5. Centralized Integration
src/queue/index.ts: Integrates the new worker/queue and ensures clean shutdown.src/queue/dashboard.ts: Registers theaccounting-syncqueue on the Bull-board admin UI.Testing Strategy & Coverage
A dedicated Jest suite has been developed to validate every potential outcome deterministically without real Redis dependencies, preventing socket connection pollution (
ECONNREFUSEDerrors).tests/queue/accountingSync.test.tsRateLimitErrorand ensures BullMQ retains the job for retry.NetworkErrorand ensures it schedules retries under exponential backoff.ValidationErrorcauses immediate job discarding.How to Verify