-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathmiddleware_test.go
28 lines (22 loc) · 1001 Bytes
/
middleware_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package river
import (
"context"
"github.com/riverqueue/river/rivertype"
)
type overridableJobMiddleware struct {
MiddlewareDefaults
insertManyFunc func(ctx context.Context, manyParams []*rivertype.JobInsertParams, doInner func(ctx context.Context) ([]*rivertype.JobInsertResult, error)) ([]*rivertype.JobInsertResult, error)
workFunc func(ctx context.Context, job *rivertype.JobRow, doInner func(ctx context.Context) error) error
}
func (m *overridableJobMiddleware) InsertMany(ctx context.Context, manyParams []*rivertype.JobInsertParams, doInner func(ctx context.Context) ([]*rivertype.JobInsertResult, error)) ([]*rivertype.JobInsertResult, error) {
if m.insertManyFunc != nil {
return m.insertManyFunc(ctx, manyParams, doInner)
}
return doInner(ctx)
}
func (m *overridableJobMiddleware) Work(ctx context.Context, job *rivertype.JobRow, doInner func(ctx context.Context) error) error {
if m.workFunc != nil {
return m.workFunc(ctx, job, doInner)
}
return doInner(ctx)
}