Honour Retry-After when a webhook receiver asks us to wait

Node · Node · intermediate · modification

Some receivers answer `429` or `503` with a `Retry-After` header, and we kept retrying on our own schedule, sometimes seconds after being told to wait ten minutes. This adds `src/webhooks/retryAfter.js`, whose `parseRetryAfter(value, nowMs)` turns the header into a delay in milliseconds (or `null` when it is missing or not usable), and uses it in `src/webhooks/deliver.js`: on a 429 or 503 the retry waits for the longer of the receiver's delay and our backoff, capped at one hour, the ceiling the backoff already has. `deliver` gains a `now` option for the clock. New unit tests in `test/webhooks/retryAfter.test.js`; `test/webhooks/deliver.test.js` gains the Retry-After cases.

Webhook delivery service on Node 22 (CommonJS), using the built-in `fetch` and `node:test` (`node --test test/`). Existing and unchanged: `src/webhooks/worker.js` claims due jobs from the `webhook_jobs` table one at a time, calls `deliver(job)` with `job.attempt` the 1-based number of this attempt (an integer from 1 to `MAX_ATTEMPTS`), and stores the outcome: `delivered` and `failed` are final, `retry` sets `next_attempt_at` to its clock plus `delayMs` and `attempt` to `attempt + 1`. `job.url` (an HTTPS URL checked when the customer registered it), `job.body` (a JSON string) and `job.signature` are set when the event is enqueued. Receivers are customers' endpoints: some rate-limit with 429 and some answer 503 during maintenance, sometimes with `Retry-After`. Our servers and the receivers keep NTP time, so a date is compared with our clock as is. In the last 90 days of delivery logs every `Retry-After` was delta-seconds or an IMF-fixdate, so the team chose to treat the obsolete date forms as unusable rather than parse them.

Requirements

Files touched

Review this PR

Node practice