-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathhook_defaults_funcs.go
More file actions
54 lines (38 loc) · 1.99 KB
/
hook_defaults_funcs.go
File metadata and controls
54 lines (38 loc) · 1.99 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package river
import (
"context"
"github.com/riverqueue/river/rivertype"
)
// HookDefaults should be embedded on any hooks implementation. It helps
// identify a struct as hooks, and guarantee forward compatibility in case
// additions are necessary to the rivertype.Hook interface.
type HookDefaults struct{}
func (d *HookDefaults) IsHook() bool { return true }
// HookInsertBeginFunc is a convenience helper for implementing
// rivertype.HookInsertBegin using a simple function instead of a struct.
type HookInsertBeginFunc func(ctx context.Context, params *rivertype.JobInsertParams) error
func (f HookInsertBeginFunc) InsertBegin(ctx context.Context, params *rivertype.JobInsertParams) error {
return f(ctx, params)
}
func (f HookInsertBeginFunc) IsHook() bool { return true }
// HookPeriodicJobsStartFunc is a convenience helper for implementing
// rivertype.HookPeriodicJobsStart using a simple function instead of a struct.
type HookPeriodicJobsStartFunc func(ctx context.Context, params *rivertype.HookPeriodicJobsStartParams) error
func (f HookPeriodicJobsStartFunc) IsHook() bool { return true }
func (f HookPeriodicJobsStartFunc) Start(ctx context.Context, params *rivertype.HookPeriodicJobsStartParams) error {
return f(ctx, params)
}
// HookWorkBeginFunc is a convenience helper for implementing
// rivertype.HookWorkBegin using a simple function instead of a struct.
type HookWorkBeginFunc func(ctx context.Context, job *rivertype.JobRow) error
func (f HookWorkBeginFunc) WorkBegin(ctx context.Context, job *rivertype.JobRow) error {
return f(ctx, job)
}
func (f HookWorkBeginFunc) IsHook() bool { return true }
// HookWorkEndFunc is a convenience helper for implementing
// rivertype.HookWorkEnd using a simple function instead of a struct.
type HookWorkEndFunc func(ctx context.Context, job *rivertype.JobRow, err error) error
func (f HookWorkEndFunc) WorkEnd(ctx context.Context, job *rivertype.JobRow, err error) error {
return f(ctx, job, err)
}
func (f HookWorkEndFunc) IsHook() bool { return true }