Remove post-persist ambiguity and have events match emitted state - #1350
Draft
brandur wants to merge 1 commit into
Draft
Remove post-persist ambiguity and have events match emitted state#1350brandur wants to merge 1 commit into
brandur wants to merge 1 commit into
Conversation
This one's aimed at fixing [1] in which for some sequences in workers, we'd emit a surprising event based on the state that was actually persisted to the database. This contract was also not stable, and changed subtly with the introduction of #1219. From [1], this is best illustrated by a short example where we error after invoking `JobCompleteTx`: func (w *Worker) Work(ctx context.Context, job *river.Job[Args]) error { tx, _ := w.dbPool.Begin(ctx) defer tx.Rollback(ctx) river.JobCompleteTx[*riverpgxv5.Driver](ctx, tx, job) // row -> completed tx.Commit(ctx) return errors.New("boom") // executor reports an error, but its UPDATE is an IfRunning no-op } This used to emit a `job_completed`, but has changed in `master` to emit a `job_failed`. Here, we try to correct the emitted event and officially standardize it: | Scenario | Persisted state | Previous event | New event | |---|---:|---:|---:| | `JobCompleteTx` commits, then worker returns an error | `completed` | `job_failed` | `job_completed` | | Remote cancellation, then worker requests a retry | `cancelled` | `job_failed` | `job_cancelled` | | Remote cancellation, then worker snoozes | `cancelled` | `job_snoozed` | `job_cancelled` | Unambiguous persisted states always take precedence, though we retain reason (added in #1219) to distinguish possible states of `available`, which may be (1) an immediate retry after failure, (2) a short snooze, or (3) an interruption caused by client shutdown. [1] #1290 (comment)
brandur
force-pushed
the
brandur-events-persist-state
branch
from
August 13, 2026 01:26
e4d6dcc to
4c45612
Compare
brandur
marked this pull request as draft
August 13, 2026 01:28
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.
This one's aimed at fixing [1] in which for some sequences in workers,
we'd emit a surprising event based on the state that was actually
persisted to the database. This contract was also not stable, and
changed subtly with the introduction of #1219.
From [1], this is best illustrated by a short example where we error
after invoking
JobCompleteTx:This used to emit a
job_completed, but has changed inmasterto emita
job_failed.Here, we try to correct the emitted event and officially standardize it:
JobCompleteTxcommits, then worker returns an errorcompletedjob_failedjob_completedcancelledjob_failedjob_cancelledcancelledjob_snoozedjob_cancelledUnambiguous persisted states always take precedence, though we retain
reason (added in #1219) to distinguish possible states of
available,which may be (1) an immediate retry after failure, (2) a short snooze,
or (3) an interruption caused by client shutdown.
[1] #1290 (comment)