Description
The background worker handles asynchronous events such as settlement notifications and external anchor updates. When external endpoints fail or time out during webhook delivery, requests need structured retry logic with exponential backoff rather than immediate failure or raw retries.
Context & Requirements
- Background tasks run via
src/worker/index.ts.
- Prisma manages database state for webhook logs and task queues.
- Webhooks must retry up to 5 times using exponential backoff (e.g., 30s, 2m, 10m, 30m, 2h).
- Failed delivery metadata (HTTP status, error message, attempt count, next retry timestamp) must be tracked in the database.
Acceptance Criteria
Implementation Guidance
- Modify Prisma schema in
prisma/schema.prisma if retry tracking fields are missing.
- Implement backoff schedule helper function in
src/services/webhookService.ts.
- Update processing loop in
src/worker/index.ts to fetch records using Prisma filtered by status and nextRetryAt.
Testing & Validation
- Run unit tests with
npm test verifying backoff timing functions.
- Run integration tests with
npm run test:integration testing webhook failure state updates.
Submission Guidelines
- Open a PR that includes "Closes #".
- Ensure assignment before beginning work.
- Maintain existing code format and linting with
npm run lint.
Wave complexity: Medium
Description
The background worker handles asynchronous events such as settlement notifications and external anchor updates. When external endpoints fail or time out during webhook delivery, requests need structured retry logic with exponential backoff rather than immediate failure or raw retries.
Context & Requirements
src/worker/index.ts.Acceptance Criteria
attemptCount,nextRetryAt,status,lastError) to webhook delivery records.src/worker/index.tsto query pending webhooks wherenextRetryAtis less than or equal to current time.Implementation Guidance
prisma/schema.prismaif retry tracking fields are missing.src/services/webhookService.ts.src/worker/index.tsto fetch records using Prisma filtered by status andnextRetryAt.Testing & Validation
npm testverifying backoff timing functions.npm run test:integrationtesting webhook failure state updates.Submission Guidelines
npm run lint.Wave complexity: Medium