Skip to content

Commit

Permalink
also clear unique_key when should_cancel (#560)
Browse files Browse the repository at this point in the history
While doing some work on a related query, I noticed that the
`unique_key` is being cleared here specifically if the new state is
explicitly `cancelled`, but _not_ if the state is being set to cancel
because of a cancellation attempt that didn't get picked up before the
job completed.

I didn't yet add test coverage for this but wanted to at least commit it
before I forgot.
  • Loading branch information
bgentry authored Aug 28, 2024
1 parent bbb4a98 commit 958d4a6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions riverdriver/riverdatabasesql/internal/dbsqlc/river_job.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions riverdriver/riverpgxv5/internal/dbsqlc/river_job.sql
Original file line number Diff line number Diff line change
Expand Up @@ -434,18 +434,18 @@ WITH job_to_update AS (
updated_job AS (
UPDATE river_job
SET
state = CASE WHEN should_cancel THEN 'cancelled'::river_job_state
state = CASE WHEN should_cancel THEN 'cancelled'::river_job_state
ELSE @state::river_job_state END,
finalized_at = CASE WHEN should_cancel THEN now()
WHEN @finalized_at_do_update::boolean THEN @finalized_at
finalized_at = CASE WHEN should_cancel THEN now()
WHEN @finalized_at_do_update::boolean THEN @finalized_at
ELSE finalized_at END,
errors = CASE WHEN @error_do_update::boolean THEN array_append(errors, @error::jsonb)
errors = CASE WHEN @error_do_update::boolean THEN array_append(errors, @error::jsonb)
ELSE errors END,
max_attempts = CASE WHEN NOT should_cancel AND @max_attempts_update::boolean THEN @max_attempts
max_attempts = CASE WHEN NOT should_cancel AND @max_attempts_update::boolean THEN @max_attempts
ELSE max_attempts END,
scheduled_at = CASE WHEN NOT should_cancel AND @scheduled_at_do_update::boolean THEN sqlc.narg('scheduled_at')::timestamptz
scheduled_at = CASE WHEN NOT should_cancel AND @scheduled_at_do_update::boolean THEN sqlc.narg('scheduled_at')::timestamptz
ELSE scheduled_at END,
unique_key = CASE WHEN @state IN ('cancelled', 'discarded') THEN NULL
unique_key = CASE WHEN (@state IN ('cancelled', 'discarded') OR should_cancel) THEN NULL
ELSE unique_key END
FROM job_to_update
WHERE river_job.id = job_to_update.id
Expand Down
14 changes: 7 additions & 7 deletions riverdriver/riverpgxv5/internal/dbsqlc/river_job.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 958d4a6

Please sign in to comment.