forked from riverqueue/river
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware_test.go
29 lines (23 loc) · 1.1 KB
/
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
29
package river
import (
"context"
"github.com/riverqueue/river/rivertype"
)
type overridableJobMiddleware struct {
JobInsertMiddlewareDefaults
WorkerMiddlewareDefaults
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 m.JobInsertMiddlewareDefaults.InsertMany(ctx, manyParams, doInner)
}
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 m.WorkerMiddlewareDefaults.Work(ctx, job, doInner)
}