forked from libi/dcron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
66 lines (57 loc) · 1.49 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
package dcron
import (
"github.com/robfig/cron/v3"
"log"
"time"
)
type Option func(*Dcron)
// WithLogger both set dcron and cron logger.
func WithLogger(logger *log.Logger) Option {
return func(dcron *Dcron) {
//set dcron logger
dcron.logger = logger
//set cron logger
f := cron.WithLogger(cron.PrintfLogger(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)
}
}