Skip to content

Commit a handler's write with its job's completion - #3

Open
zaiev wants to merge 1 commit into
mainfrom
commit-a-handlers-write-with-its-jobs-completion
Open

zaiev wants to merge 1 commit into
mainfrom
commit-a-handlers-write-with-its-jobs-completion

Conversation

@zaiev

@zaiev zaiev commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Why

A handler wrote to the application's tables in a transaction of its own, before the runner recorded the job complete in another, so a runner that died between the two ran the job again and wrote twice. Saving results for spool to keep, and awaiting them, was weighed and left out: the application's own tables are where its results belong.

Changes

  • Spool.handle_committing: a handler answers a write, made in the transaction that completes its job, after the statement guarded by the lease; the job is completed and the write made together, or neither.
  • A write that fails rolls the completion back and is the attempt's failure; one that raises is a retry named by its constructor; a runner whose lease was taken makes none.
  • Spool.handle is unchanged: a handler with nothing to write is written as before.

Verified

  • make lint and make test: 83 tests, six new against a real Postgres, each seen failing when the write ran without the lease or a failed write was ignored.
  • make docs: the site built, its link check passing.

A handler wrote to the application's tables in a transaction of its own,
before the runner recorded the job complete in another, so a runner that
died between the two ran the job again and wrote twice, and every
application kept its writes idempotent by hand. handle_committing has the
handler answer its write, which the runner makes in the transaction that
completes the job, after the statement guarded by the lease: the job is
completed and the write made together, or neither, and a runner whose
lease was taken makes none. A write that fails rolls the completion back
and is the attempt's failure. Saving results for spool to keep, and
awaiting them, was weighed and left out: the application's own tables
are where its results belong.

This branch has not been deployed

No deployments
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.

1 participant