Skip to content

Commit

Permalink
fix river.JobCancel with nil arg (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgentry authored Oct 5, 2024
1 parent 5dd7f7c commit 4876b52
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Breaking change:** The advisory lock unique jobs implementation which was deprecated in v0.12.0 has been removed. Users of that feature should first upgrade to v0.12.1 to ensure they don't see any warning logs about using the deprecated advisory lock uniqueness. The new, faster unique implementation will be used automatically as long as the `UniqueOpts.ByState` list hasn't been customized to remove [required states](https://riverqueue.com/docs/unique-jobs#unique-by-state) (`pending`, `scheduled`, `available`, and `running`). As of this release, customizing `ByState` without these required states returns an error. [PR #614](https://github.com/riverqueue/river/pull/614).
- Single job inserts are now unified under the hood to use the `InsertMany` bulk insert query. This should not be noticeable to users, and the unified code path will make it easier to build new features going forward. [PR #614](https://github.com/riverqueue/river/pull/614).

### Fixed

- Allow `river.JobCancel` to accept a `nil` error as input without panicking. [PR #634](https://github.com/riverqueue/river/pull/634).

## [0.12.1] - 2024-09-26

### Changed
Expand Down
30 changes: 30 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,36 @@ func Test_Client(t *testing.T) {
require.WithinDuration(t, time.Now(), *updatedJob.FinalizedAt, 2*time.Second)
})

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

client, _ := setup(t)

type JobArgs struct {
JobArgsReflectKind[JobArgs]
}

AddWorker(client.config.Workers, WorkFunc(func(ctx context.Context, job *Job[JobArgs]) error {
return JobCancel(nil)
}))

subscribeChan := subscribe(t, client)
startClient(ctx, t, client)

insertRes, err := client.Insert(ctx, &JobArgs{}, nil)
require.NoError(t, err)

event := riversharedtest.WaitOrTimeout(t, subscribeChan)
require.Equal(t, EventKindJobCancelled, event.Kind)
require.Equal(t, rivertype.JobStateCancelled, event.Job.State)
require.WithinDuration(t, time.Now(), *event.Job.FinalizedAt, 2*time.Second)

updatedJob, err := client.JobGet(ctx, insertRes.Job.ID)
require.NoError(t, err)
require.Equal(t, rivertype.JobStateCancelled, updatedJob.State)
require.WithinDuration(t, time.Now(), *updatedJob.FinalizedAt, 2*time.Second)
})

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

Expand Down
3 changes: 3 additions & 0 deletions job_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type jobCancelError struct {
}

func (e *jobCancelError) Error() string {
if e.err == nil {
return "jobCancelError: <nil>"
}
// should not ever be called, but add a prefix just in case:
return "jobCancelError: " + e.err.Error()
}
Expand Down

0 comments on commit 4876b52

Please sign in to comment.