-
Notifications
You must be signed in to change notification settings - Fork 75
/
option.go
89 lines (76 loc) · 2.06 KB
/
option.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
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package dcron
import (
"time"
"github.com/dcron-contrib/commons/dlog"
"github.com/libi/dcron/cron"
)
// Option is Dcron Option
type Option func(*Dcron)
// WithLogger both set dcron and cron logger.
func WithLogger(logger dlog.Logger) Option {
return func(dcron *Dcron) {
//set dcron logger
dcron.logger = logger
f := cron.WithLogger(logger)
dcron.crOptions = append(dcron.crOptions, f)
}
}
// WithNodeUpdateDuration set node update duration
func WithNodeUpdateDuration(d time.Duration) Option {
return func(dcron *Dcron) {
dcron.nodeUpdateDuration = d
}
}
// WithHashReplicas set hashReplicas
func WithHashReplicas(d int) Option {
return func(dcron *Dcron) {
dcron.hashReplicas = d
}
}
// CronOptionLocation is warp cron with location
func CronOptionLocation(loc *time.Location) Option {
return func(dcron *Dcron) {
f := cron.WithLocation(loc)
dcron.crOptions = append(dcron.crOptions, f)
}
}
// CronOptionSeconds is warp cron with seconds
func CronOptionSeconds() Option {
return func(dcron *Dcron) {
f := cron.WithSeconds()
dcron.crOptions = append(dcron.crOptions, f)
}
}
// CronOptionParser is warp cron with schedules.
func CronOptionParser(p cron.ScheduleParser) Option {
return func(dcron *Dcron) {
f := cron.WithParser(p)
dcron.crOptions = append(dcron.crOptions, f)
}
}
// CronOptionChain is Warp cron with chain
func CronOptionChain(wrappers ...cron.JobWrapper) Option {
return func(dcron *Dcron) {
f := cron.WithChain(wrappers...)
dcron.crOptions = append(dcron.crOptions, f)
}
}
// You can defined yourself recover function to make the
// job will be added to your dcron when the process restart
func WithRecoverFunc(recoverFunc RecoverFuncType) Option {
return func(dcron *Dcron) {
dcron.RecoverFunc = recoverFunc
}
}
// You can use this option to start the recent jobs rerun
// after the cluster upgrading.
func WithClusterStable(timeWindow time.Duration) Option {
return func(d *Dcron) {
d.recentJobs = NewRecentJobPacker(timeWindow)
}
}
func RunningLocally() Option {
return func(d *Dcron) {
d.runningLocally = true
}
}