-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
59 lines (50 loc) · 1.57 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
package cron
import (
redsyncredis "github.com/go-redsync/redsync/v4/redis"
"time"
)
// Option represents a modification to the default behavior of a Cron.
type Option func(*Cron)
// WithLocation overrides the timezone of the cron instance.
func WithLocation(loc *time.Location) Option {
return func(c *Cron) {
c.location = loc
}
}
// WithSeconds overrides the parser used for interpreting job schedules to
// include a seconds field as the first one.
func WithSeconds() Option {
return WithParser(NewParser(
Second | Minute | Hour | Dom | Month | Dow | Descriptor,
))
}
// WithParser overrides the parser used for interpreting job schedules.
func WithParser(p ScheduleParser) Option {
return func(c *Cron) {
c.parser = p
}
}
// WithChain specifies Job wrappers to apply to all jobs added to this cron.
// Refer to the Chain* functions in this package for provided wrappers.
func WithChain(wrappers ...JobWrapper) Option {
return func(c *Cron) {
c.chain = NewChain(wrappers...)
}
}
// WithLogger uses the provided logger.
func WithLogger(logger Logger) Option {
return func(c *Cron) {
c.logger = logger
}
}
// WithLocks specifies JobLocker realization for all jobs added to this cron.
func WithLocks(locker JobLocker) Option {
return func(c *Cron) {
c.jobLocker = locker
}
}
// WithRedsyncLocker specifies a built-in implementation of JobLocker with redsync distributed lock.
// Redis-based distributed mutual exclusion lock https://github.com/go-redsync/redsync
func WithRedsyncLocker(pools ...redsyncredis.Pool) Option {
return WithLocks(newRedisLocker(pools...))
}