Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed `rivertest.Worker` to honor a configured `Config.JobStuckThreshold` for stuck job detection. Previously, it always used an internal 5 second threshold, so the `Job appears to be stuck` log line was emitted at a different time than it would be under a real client. [PR #1418](https://github.com/riverqueue/river/pull/1418).
- Fixed SQLite job cleanup stalling when excluded queues fill the oldest batch, and added support for included queue filters so per-queue retention works on SQLite. [PR #1417](https://github.com/riverqueue/river/pull/1417).
- Fixed a unique insert skipped as a duplicate of a job of a different kind (possible with `UniqueOpts.ExcludeKind`) changing the existing job's kind to its own. [PR #1421](https://github.com/riverqueue/river/pull/1421).

## [0.48.0] - 2026-09-30

Expand Down

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

43 changes: 43 additions & 0 deletions riverdriver/riverdrivertest/job_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,49 @@ func exerciseJobInsert[TTx any](ctx context.Context, t *testing.T,
require.Equal(t, results1[0].Job.ID, results2[0].Job.ID)
})

// With UniqueOpts.ExcludeKind, jobs of different kinds share a unique
// key. A skipped insert must return the incumbent row unmodified rather
// than rewriting its kind to the kind of the skipped job.
t.Run("UniqueConflictDifferentKindLeavesIncumbentKind", func(t *testing.T) {
t.Parallel()

exec, _ := setup(ctx, t)

insertParams := func(kind string) *riverdriver.JobInsertFastManyParams {
return &riverdriver.JobInsertFastManyParams{
Jobs: []*riverdriver.JobInsertFastParams{
{
EncodedArgs: []byte(`{"encoded": "args"}`),
Kind: kind,
MaxAttempts: rivercommon.MaxAttemptsDefault,
Priority: rivercommon.PriorityDefault,
Queue: rivercommon.QueueDefault,
State: rivertype.JobStateAvailable,
Tags: []string{},
UniqueKey: []byte("unique-key-exclude-kind"),
UniqueStates: 0xff,
},
},
}
}

results1, err := exec.JobInsertFastMany(ctx, insertParams("kind_a"))
require.NoError(t, err)
require.Len(t, results1, 1)
require.False(t, results1[0].UniqueSkippedAsDuplicate)

results2, err := exec.JobInsertFastMany(ctx, insertParams("kind_b"))
require.NoError(t, err)
require.Len(t, results2, 1)
require.True(t, results2[0].UniqueSkippedAsDuplicate)
require.Equal(t, results1[0].Job.ID, results2[0].Job.ID)
require.Equal(t, "kind_a", results2[0].Job.Kind)

job, err := exec.JobGetByID(ctx, &riverdriver.JobGetByIDParams{ID: results1[0].Job.ID})
require.NoError(t, err)
require.Equal(t, "kind_a", job.Kind)
})

t.Run("UniqueConflictWithinBatch", func(t *testing.T) {
t.Parallel()

Expand Down
3 changes: 2 additions & 1 deletion riverdriver/riverpgxv5/internal/dbsqlc/river_job.sql
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ ON CONFLICT (unique_key)
AND unique_states IS NOT NULL
AND /* TEMPLATE: schema */river_job_state_in_bitmask(unique_states, state)
-- Something needs to be updated for a row to be returned on a conflict.
DO UPDATE SET kind = EXCLUDED.kind
-- Keep the existing kind, which may differ under `ExcludeKind`.
DO UPDATE SET kind = river_job.kind
RETURNING
sqlc.embed(river_job),
/* TEMPLATE_BEGIN: unique_skipped_as_duplicate */ (xmax != 0) /* TEMPLATE_END */ AS unique_skipped_as_duplicate;
Expand Down
3 changes: 2 additions & 1 deletion 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.

6 changes: 4 additions & 2 deletions riverdriver/riversqlite/internal/dbsqlc/river_job.sql
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ ON CONFLICT (unique_key)
ELSE 0
END >= 1
-- Something needs to be updated for a row to be returned on a conflict.
DO UPDATE SET kind = EXCLUDED.kind
-- Keep the existing kind, which may differ under `ExcludeKind`.
DO UPDATE SET kind = river_job.kind
RETURNING *;

-- name: JobInsertFastMany :many
Expand Down Expand Up @@ -340,7 +341,8 @@ ON CONFLICT (unique_key)
ELSE 0
END >= 1
-- Something needs to be updated for a row to be returned on a conflict.
DO UPDATE SET kind = EXCLUDED.kind
-- Keep the existing kind, which may differ under `ExcludeKind`.
DO UPDATE SET kind = river_job.kind
RETURNING *;

-- name: JobInsertFastNoReturning :execrows
Expand Down
6 changes: 4 additions & 2 deletions riverdriver/riversqlite/internal/dbsqlc/river_job.sql.go

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

Loading