Skip to content

Invoice Batch Processor with Concurrency Limiter #527

Description

@Kingsman-99

Description

When an integration needs to process dozens of invoices simultaneously (e.g. month-end batch billing), running all submissions concurrently overwhelms Horizon's rate limits and produces cascading 429 errors. The SDK must provide a batch processor that submits invoices with a configurable concurrency ceiling, respects rate-limit backoff signals, and reports per-invoice results as they settle rather than waiting for the entire batch.

Technical Context

Add src/invoiceBatchProcessor.ts. Extends src/requestBatcher.ts patterns. Uses a semaphore pattern (configurable maxConcurrent, default 3) wrapping src/client.ts submitPayment(). Integrates with src/rateLimiter.ts to detect and honour Retry-After headers. Emits batchInvoiceSettled and batchInvoiceFailed via src/events.ts. Returns AsyncIterableIterator<BatchInvoiceResult>.

Acceptance Criteria

  • InvoiceBatchProcessor.process(invoiceIds: string[], config): AsyncIterableIterator<BatchInvoiceResult> yields results as each invoice settles
  • No more than maxConcurrent invoice submissions are in-flight simultaneously
  • On 429 response from Horizon, pauses all in-flight submissions for the duration specified in Retry-After and resumes
  • BatchInvoiceResult includes invoiceId, status: 'success' | 'failed', txHash?, and error?
  • Failed invoices are reported individually without aborting the rest of the batch
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions