Conversation
…very
The `state` column duplicated information already carried by `acquired_token`:
`state='processing'` was equivalent to `acquired_token IS NOT NULL`. The
redundancy required a third async loop (`_release_stuck_loop`) to flip stuck
rows back to `pending` plus a Postgres advisory lock to coordinate that loop
across replicas.
Replace both with a single lease check inside the fetch CTE: a row is available
iff its lease is unset *or* expired (`acquired_at < now() - lease_ttl_seconds`).
This deletes ~50 lines, drops one async task per subscriber, and shrinks
worst-case crash recovery from ~7.5 min to ~60s with the new default TTL.
Breaking changes:
- `OutboxState` enum removed from public exports.
- `state` column dropped from `make_outbox_table`.
- `OutboxClient.release_stuck` removed.
- `release_stuck_timeout` + `release_stuck_interval` kwargs replaced with
single `lease_ttl_seconds: float = 60.0` (was `release_stuck_timeout=300.0`)
on `subscriber()`, `OutboxRoute`, and `create_subscriber`.
- `OutboxClient.fetch` requires new `lease_ttl_seconds` kwarg.
Migration:
ALTER TABLE outbox DROP CONSTRAINT outbox_state_check;
ALTER TABLE outbox DROP COLUMN state;
DROP INDEX IF EXISTS outbox_pending_idx;
CREATE INDEX outbox_pending_idx ON outbox (queue, next_attempt_at)
WHERE acquired_token IS NULL;
103 tests pass with 100% coverage.
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.
The
statecolumn duplicated information already carried byacquired_token:state='processing'was equivalent toacquired_token IS NOT NULL. The redundancy required a third async loop (_release_stuck_loop) to flip stuck rows back topendingplus a Postgres advisory lock to coordinate that loop across replicas.Replace both with a single lease check inside the fetch CTE: a row is available iff its lease is unset or expired (
acquired_at < now() - lease_ttl_seconds). This deletes ~50 lines, drops one async task per subscriber, and shrinks worst-case crash recovery from ~7.5 min to ~60s with the new default TTL.Breaking changes:
OutboxStateenum removed from public exports.statecolumn dropped frommake_outbox_table.OutboxClient.release_stuckremoved.release_stuck_timeout+release_stuck_intervalkwargs replaced with singlelease_ttl_seconds: float = 60.0(wasrelease_stuck_timeout=300.0) onsubscriber(),OutboxRoute, andcreate_subscriber.OutboxClient.fetchrequires newlease_ttl_secondskwarg.Migration:
103 tests pass with 100% coverage.