From 958d4a6139bfc5f290ecb9fc204e0c2f186c0df9 Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Wed, 28 Aug 2024 10:35:00 -0500 Subject: [PATCH] also clear unique_key when should_cancel (#560) 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. --- .../internal/dbsqlc/river_job.sql.go | 14 +++++++------- .../riverpgxv5/internal/dbsqlc/river_job.sql | 14 +++++++------- .../riverpgxv5/internal/dbsqlc/river_job.sql.go | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/riverdriver/riverdatabasesql/internal/dbsqlc/river_job.sql.go b/riverdriver/riverdatabasesql/internal/dbsqlc/river_job.sql.go index e1c1a036..61eebd1d 100644 --- a/riverdriver/riverdatabasesql/internal/dbsqlc/river_job.sql.go +++ b/riverdriver/riverdatabasesql/internal/dbsqlc/river_job.sql.go @@ -1094,18 +1094,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 $1::river_job_state END, - finalized_at = CASE WHEN should_cancel THEN now() - WHEN $3::boolean THEN $4 + finalized_at = CASE WHEN should_cancel THEN now() + WHEN $3::boolean THEN $4 ELSE finalized_at END, - errors = CASE WHEN $5::boolean THEN array_append(errors, $6::jsonb) + errors = CASE WHEN $5::boolean THEN array_append(errors, $6::jsonb) ELSE errors END, - max_attempts = CASE WHEN NOT should_cancel AND $7::boolean THEN $8 + max_attempts = CASE WHEN NOT should_cancel AND $7::boolean THEN $8 ELSE max_attempts END, - scheduled_at = CASE WHEN NOT should_cancel AND $9::boolean THEN $10::timestamptz + scheduled_at = CASE WHEN NOT should_cancel AND $9::boolean THEN $10::timestamptz ELSE scheduled_at END, - unique_key = CASE WHEN $1 IN ('cancelled', 'discarded') THEN NULL + unique_key = CASE WHEN ($1 IN ('cancelled', 'discarded') OR should_cancel) THEN NULL ELSE unique_key END FROM job_to_update WHERE river_job.id = job_to_update.id diff --git a/riverdriver/riverpgxv5/internal/dbsqlc/river_job.sql b/riverdriver/riverpgxv5/internal/dbsqlc/river_job.sql index 373bede8..ff3decf2 100644 --- a/riverdriver/riverpgxv5/internal/dbsqlc/river_job.sql +++ b/riverdriver/riverpgxv5/internal/dbsqlc/river_job.sql @@ -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 diff --git a/riverdriver/riverpgxv5/internal/dbsqlc/river_job.sql.go b/riverdriver/riverpgxv5/internal/dbsqlc/river_job.sql.go index 5117a28f..5beabbe6 100644 --- a/riverdriver/riverpgxv5/internal/dbsqlc/river_job.sql.go +++ b/riverdriver/riverpgxv5/internal/dbsqlc/river_job.sql.go @@ -1074,18 +1074,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 $1::river_job_state END, - finalized_at = CASE WHEN should_cancel THEN now() - WHEN $3::boolean THEN $4 + finalized_at = CASE WHEN should_cancel THEN now() + WHEN $3::boolean THEN $4 ELSE finalized_at END, - errors = CASE WHEN $5::boolean THEN array_append(errors, $6::jsonb) + errors = CASE WHEN $5::boolean THEN array_append(errors, $6::jsonb) ELSE errors END, - max_attempts = CASE WHEN NOT should_cancel AND $7::boolean THEN $8 + max_attempts = CASE WHEN NOT should_cancel AND $7::boolean THEN $8 ELSE max_attempts END, - scheduled_at = CASE WHEN NOT should_cancel AND $9::boolean THEN $10::timestamptz + scheduled_at = CASE WHEN NOT should_cancel AND $9::boolean THEN $10::timestamptz ELSE scheduled_at END, - unique_key = CASE WHEN $1 IN ('cancelled', 'discarded') THEN NULL + unique_key = CASE WHEN ($1 IN ('cancelled', 'discarded') OR should_cancel) THEN NULL ELSE unique_key END FROM job_to_update WHERE river_job.id = job_to_update.id