Skip to content

Commit 7bb1c41

Browse files
authored
Prepare release 0.9.0 + add test for periodic job bundle (#421)
We haven't cut a new release in a while, and the bug in #420 is kind of bad, so now that there's a fix it's not a bad time to cut a new release. I'm also including a test case that catches the bug from #420. Apparently none of our other test cases can catch the problem, so it's good to have a regression guard.
1 parent 7899e20 commit 7bb1c41

6 files changed

Lines changed: 83 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.9.0] - 2024-07-04
11+
1012
### Added
1113

1214
- `Config.TestOnly` has been added. It disables various features in the River client like staggered maintenance service start that are useful in production, but may be somewhat harmful in tests because they make start/stop slower. [PR #414](https://github.com/riverqueue/river/pull/414).
@@ -28,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2830
### Fixed
2931

3032
- Pausing or resuming a queue that was already paused or not paused respectively no longer returns `rivertype.ErrNotFound`. The same goes for pausing or resuming using the all queues string (`*`) when no queues are in the database (previously that also returned `rivertype.ErrNotFound`). [PR #408](https://github.com/riverqueue/river/pull/408).
33+
- Fix a bug where periodic job constructors were only called once when adding the periodic job rather than being invoked every time the periodic job is scheduled. [PR #420](https://github.com/riverqueue/river/pull/420).
3134

3235
## [0.8.0] - 2024-06-25
3336

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ require (
1414
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
1515
github.com/jackc/pgx/v5 v5.6.0
1616
github.com/jackc/puddle/v2 v2.2.1
17-
github.com/riverqueue/river/riverdriver v0.8.0
18-
github.com/riverqueue/river/riverdriver/riverdatabasesql v0.8.0
19-
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.8.0
20-
github.com/riverqueue/river/rivertype v0.8.0
17+
github.com/riverqueue/river/riverdriver v0.9.0
18+
github.com/riverqueue/river/riverdriver/riverdatabasesql v0.9.0
19+
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.9.0
20+
github.com/riverqueue/river/rivertype v0.9.0
2121
github.com/robfig/cron/v3 v3.0.1
2222
github.com/stretchr/testify v1.9.0
2323
go.uber.org/goleak v1.3.0

periodic_job_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package river
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
"time"
7+
8+
"github.com/stretchr/testify/require"
9+
10+
"github.com/riverqueue/river/internal/maintenance"
11+
"github.com/riverqueue/river/internal/riverinternaltest"
12+
)
13+
14+
func TestPeriodicJobBundle(t *testing.T) {
15+
t.Parallel()
16+
17+
type testBundle struct{}
18+
19+
setup := func(t *testing.T) (*PeriodicJobBundle, *testBundle) {
20+
t.Helper()
21+
22+
periodicJobEnqueuer := maintenance.NewPeriodicJobEnqueuer(
23+
riverinternaltest.BaseServiceArchetype(t),
24+
&maintenance.PeriodicJobEnqueuerConfig{},
25+
nil,
26+
)
27+
28+
return newPeriodicJobBundle(newTestConfig(t, nil), periodicJobEnqueuer), &testBundle{}
29+
}
30+
31+
t.Run("ConstructorFuncGeneratesNewArgsOnEachCall", func(t *testing.T) {
32+
t.Parallel()
33+
34+
periodicJobBundle, _ := setup(t)
35+
36+
type TestJobArgs struct {
37+
JobArgsReflectKind[TestJobArgs]
38+
JobNum int `json:"job_num"`
39+
}
40+
41+
var jobNum int
42+
43+
periodicJob := NewPeriodicJob(
44+
PeriodicInterval(15*time.Minute),
45+
func() (JobArgs, *InsertOpts) {
46+
jobNum++
47+
return TestJobArgs{JobNum: jobNum}, nil
48+
},
49+
nil,
50+
)
51+
52+
internalPeriodicJob := periodicJobBundle.toInternal(periodicJob)
53+
54+
insertParams1, _, err := internalPeriodicJob.ConstructorFunc()
55+
require.NoError(t, err)
56+
require.Equal(t, 1, mustUnmarshalJSON[TestJobArgs](t, insertParams1.EncodedArgs).JobNum)
57+
58+
insertParams2, _, err := internalPeriodicJob.ConstructorFunc()
59+
require.NoError(t, err)
60+
require.Equal(t, 2, mustUnmarshalJSON[TestJobArgs](t, insertParams2.EncodedArgs).JobNum)
61+
})
62+
}
63+
64+
func mustUnmarshalJSON[T any](t *testing.T, data []byte) *T {
65+
t.Helper()
66+
67+
var val T
68+
err := json.Unmarshal(data, &val)
69+
require.NoError(t, err)
70+
return &val
71+
}

riverdriver/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ go 1.21.4
44

55
replace github.com/riverqueue/river/rivertype => ../rivertype
66

7-
require github.com/riverqueue/river/rivertype v0.8.0
7+
require github.com/riverqueue/river/rivertype v0.9.0

riverdriver/riverdatabasesql/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ replace github.com/riverqueue/river/rivertype => ../../rivertype
88

99
require (
1010
github.com/lib/pq v1.10.9
11-
github.com/riverqueue/river/riverdriver v0.8.0
12-
github.com/riverqueue/river/rivertype v0.8.0
11+
github.com/riverqueue/river/riverdriver v0.9.0
12+
github.com/riverqueue/river/rivertype v0.9.0
1313
github.com/stretchr/testify v1.9.0
1414
)
1515

riverdriver/riverpgxv5/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ replace github.com/riverqueue/river/rivertype => ../../rivertype
99
require (
1010
github.com/jackc/pgx/v5 v5.5.0
1111
github.com/jackc/puddle/v2 v2.2.1
12-
github.com/riverqueue/river/riverdriver v0.8.0
13-
github.com/riverqueue/river/rivertype v0.8.0
12+
github.com/riverqueue/river/riverdriver v0.9.0
13+
github.com/riverqueue/river/rivertype v0.9.0
1414
github.com/stretchr/testify v1.9.0
1515
)
1616

0 commit comments

Comments
 (0)