Skip to content

Commit

Permalink
include pending state by default in JobListParams
Browse files Browse the repository at this point in the history
When the pending state was added, we did not add it to the default list
of job states used by `JobList`. The filters are supposed to included
_all_ states by default, so it needs to be added.
  • Loading branch information
bgentry committed Jul 29, 2024
1 parent bf61772 commit cdc3876
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Include `pending` state in `JobListParams` by default so pending jobs are included in `JobList` / `JobListTx` results.

## [0.10.1] - 2024-07-23

### Fixed
Expand Down Expand Up @@ -69,13 +73,13 @@ river migrate-up --database-url "$DATABASE_URL"

- **Breaking change:** Add stack trace to `ErrorHandler.HandlePanicFunc`. Fixing code only requires adding a new `trace string` argument to `HandlePanicFunc`. [PR #423](https://github.com/riverqueue/river/pull/423).

``` go
# before
HandlePanic(ctx context.Context, job *rivertype.JobRow, panicVal any) *ErrorHandlerResult
```go
# before
HandlePanic(ctx context.Context, job *rivertype.JobRow, panicVal any) *ErrorHandlerResult

# after
HandlePanic(ctx context.Context, job *rivertype.JobRow, panicVal any, trace string) *ErrorHandlerResult
```
# after
HandlePanic(ctx context.Context, job *rivertype.JobRow, panicVal any, trace string) *ErrorHandlerResult
```

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ type JobListResult struct {
// provided context is used for the underlying Postgres query and can be used to
// cancel the operation or apply a timeout.
//
// params := river.NewJobListParams().WithLimit(10).State(rivertype.JobStateCompleted)
// params := river.NewJobListParams().First(10).State(rivertype.JobStateCompleted)
// jobRows, err := client.JobList(ctx, params)
// if err != nil {
// // handle error
Expand Down Expand Up @@ -1623,7 +1623,7 @@ func (c *Client[TTx]) JobList(ctx context.Context, params *JobListParams) (*JobL
// provided context is used for the underlying Postgres query and can be used to
// cancel the operation or apply a timeout.
//
// params := river.NewJobListParams().First(10).State(river.JobStateCompleted)
// params := river.NewJobListParams().First(10).States(river.JobStateCompleted)
// jobRows, err := client.JobListTx(ctx, tx, params)
// if err != nil {
// // handle error
Expand Down
6 changes: 6 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,7 @@ func Test_Client_JobList(t *testing.T) {
job1 := testfactory.Job(ctx, t, bundle.exec, &testfactory.JobOpts{State: ptrutil.Ptr(rivertype.JobStateAvailable)})
job2 := testfactory.Job(ctx, t, bundle.exec, &testfactory.JobOpts{State: ptrutil.Ptr(rivertype.JobStateAvailable)})
job3 := testfactory.Job(ctx, t, bundle.exec, &testfactory.JobOpts{State: ptrutil.Ptr(rivertype.JobStateRunning)})
job4 := testfactory.Job(ctx, t, bundle.exec, &testfactory.JobOpts{State: ptrutil.Ptr(rivertype.JobStatePending)})

listRes, err := client.JobList(ctx, NewJobListParams().States(rivertype.JobStateAvailable))
require.NoError(t, err)
Expand All @@ -2030,6 +2031,11 @@ func Test_Client_JobList(t *testing.T) {
listRes, err = client.JobList(ctx, NewJobListParams().States(rivertype.JobStateRunning))
require.NoError(t, err)
require.Equal(t, []int64{job3.ID}, sliceutil.Map(listRes.Jobs, func(job *rivertype.JobRow) int64 { return job.ID }))

// All by default:
listRes, err = client.JobList(ctx, NewJobListParams())
require.NoError(t, err)
require.Equal(t, []int64{job1.ID, job2.ID, job3.ID, job4.ID}, sliceutil.Map(listRes.Jobs, func(job *rivertype.JobRow) int64 { return job.ID }))
})

t.Run("DefaultsToOrderingByID", func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions job_list_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func NewJobListParams() *JobListParams {
rivertype.JobStateCancelled,
rivertype.JobStateCompleted,
rivertype.JobStateDiscarded,
rivertype.JobStatePending,
rivertype.JobStateRetryable,
rivertype.JobStateRunning,
rivertype.JobStateScheduled,
Expand Down

0 comments on commit cdc3876

Please sign in to comment.