Skip to content

Commit 125d93a

Browse files
authored
Deprecate per-operation middleware operation defaults (#815)
As per #804, middleware has been restructed to look more like the design of hooks, and I was finding that as I restructuring documentation as part of [1] it was hard to recommend the use of per-operation middleware defaults. Here, deprecate the per-operation defaults in favor of just the single `river.MiddlewareDefaults` struct. This should also be somewhat more beneficial in case more middleware operations need to be added in the future because we'll just have fewer total new types emerge out of it. [1] riverqueue/homepage#198
1 parent f44bfab commit 125d93a

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Changed
1111

1212
- Set minimum Go version to Go 1.23. [PR #811](https://github.com/riverqueue/river/pull/811).
13+
- Deprecate `river.JobInsertMiddlewareDefaults` and `river.WorkerMiddlewareDefaults` in favor of the more general `river.MiddlewareDefaults` embeddable struct. The two former structs will be removed in a future version. [PR #815](https://github.com/riverqueue/river/pull/815).
1314

1415
## [0.19.0] - 2025-03-16
1516

hook_defaults_funcs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"github.com/riverqueue/river/rivertype"
77
)
88

9-
// HookDefaults should be embedded on any hook implementation. It helps
10-
// guarantee forward compatibility in case additions are necessary to the Hook
11-
// interface.
9+
// HookDefaults should be embedded on any hooks implementation. It helps
10+
// identify a struct as hooks, and guarantee forward compatibility in case
11+
// additions are necessary to the rivertype.Hook interface.
1212
type HookDefaults struct{}
1313

1414
func (d *HookDefaults) IsHook() bool { return true }

middleware_defaults.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"github.com/riverqueue/river/rivertype"
77
)
88

9+
// MiddlewareDefaults should be embedded on any middleware implementation. It
10+
// helps identify a struct as middleware, and guarantees forward compatibility in
11+
// case additions are necessary to the rivertype.Middleware interface.
912
type MiddlewareDefaults struct{}
1013

1114
func (d *MiddlewareDefaults) IsMiddleware() bool { return true }
@@ -14,6 +17,8 @@ func (d *MiddlewareDefaults) IsMiddleware() bool { return true }
1417
// implementations for the rivertype.JobInsertMiddleware. Use of this struct is
1518
// recommended in case rivertype.JobInsertMiddleware is expanded in the future
1619
// so that existing code isn't unexpectedly broken during an upgrade.
20+
//
21+
// Deprecated: Prefer embedding the more general MiddlewareDefaults instead.
1722
type JobInsertMiddlewareDefaults struct{ MiddlewareDefaults }
1823

1924
func (d *JobInsertMiddlewareDefaults) InsertMany(ctx context.Context, manyParams []*rivertype.JobInsertParams, doInner func(ctx context.Context) ([]*rivertype.JobInsertResult, error)) ([]*rivertype.JobInsertResult, error) {
@@ -24,6 +29,8 @@ func (d *JobInsertMiddlewareDefaults) InsertMany(ctx context.Context, manyParams
2429
// implementations for the rivertype.WorkerMiddleware. Use of this struct is
2530
// recommended in case rivertype.WorkerMiddleware is expanded in the future so
2631
// that existing code isn't unexpectedly broken during an upgrade.
32+
//
33+
// Deprecated: Prefer embedding the more general MiddlewareDefaults instead.
2734
type WorkerMiddlewareDefaults struct{ MiddlewareDefaults }
2835

2936
func (d *WorkerMiddlewareDefaults) Work(ctx context.Context, job *rivertype.JobRow, doInner func(ctx context.Context) error) error {

0 commit comments

Comments
 (0)