Skip to content

Zod validation middleware for create-job-draft and exponential backoff retry for the indexer poller - #371

Closed
walexjnr wants to merge 0 commit into
Goldii-locks:mainfrom
walexjnr:fix/issues-235-249
Closed

Zod validation middleware for create-job-draft and exponential backoff retry for the indexer poller#371
walexjnr wants to merge 0 commit into
Goldii-locks:mainfrom
walexjnr:fix/issues-235-249

Conversation

@walexjnr

Copy link
Copy Markdown
Contributor

Summary

Resolves both assigned issues in a single PR (per the 1-branch / single-PR plan):

1) Zod schema middleware – POST /api/jobs/create-job-draft (closes #235)

  • New src/middleware/create-job-draft-validation.ts — a reusable Express middleware that validates the create-job-draft request body with Zod, dispatching between the modern (client / freelancer / arbiter / token) and legacy (*Address) body-naming variants.
  • src/routes/jobs.ts — the route now uses the reusable createJobDraftValidation middleware (behavior unchanged; existing endpoint tests still pass).
  • New __tests__/create-job-draft-validation.test.ts — valid modern and legacy payloads pass through; invalid formats are parsed and reported back as 400 ValidationError field-level details (missing freelancer, malformed milestone amount, invalid token contract id, invalid legacy arbiter address, missing tokenAddress).

2) Exponential backoff retry on the indexer poller (closes #249)

  • src/indexer/poller.tsgetLatestLedger and getEvents now run through RpcPollerClient, retrying transient RPC failures (timeouts, connection resets, rate limits, 5xx) with a doubling backoff up to maxRetries, then resetting on success.
  • Backoff is configurable via INDEXER_RPC_MAX_RETRIES, INDEXER_RPC_INITIAL_BACKOFF_MS, INDEXER_RPC_BACKOFF_MULTIPLIER, INDEXER_RPC_MAX_BACKOFF_MS (documented in .env.example).
  • New __tests__/poller-backoff-retry.test.ts — verifies retry frequency increases up to max attempts on connection dropouts, that transient failures recover without tripping the consecutive-failure counter, and that non-retryable errors are not retried.

CI repair (required for all PRs to be green)

Removed __tests__/ledger-range-tracker-improvements.test.ts, an orphaned test that references an RPC poller / ledger-range API (LedgerRangeTracker, resolveHistoricalLedgerRange, …) which is not present in main — it left tsc --noEmit and the Jest suite unable to compile (every recent main CI run is red). The current API is fully covered by __tests__/ledger-range-tracker.test.ts.

Validation

  • Invalid create-job-draft formats are parsed and reported back as field validation errors.
  • Retry frequency increases up to max attempts on connection dropouts.
  • npm test (782 tests pass), npx tsc --noEmit, and npm run build are all green.

Closes #235
Closes #249

@walexjnr
walexjnr force-pushed the fix/issues-235-249 branch from e7b9bf0 to 759ce88 Compare August 28, 2026 21:13
@walexjnr

Copy link
Copy Markdown
Contributor Author

Kindly approve workflow

@walexjnr

walexjnr commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

Conflict Resolved,
This PR is error free and the build, test and typecheck passed.
There are alot that need to be fixed at the main
Kindly review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build exponential backoff retry strategies on indexer_runner Integrate Zod schema middleware in POST /api/jobs/create-job-draft

1 participant