-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
52 lines (44 loc) · 1.15 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
package cron
import (
"context"
"time"
)
// Option represents a modification to the default behavior of a Cron.
type Option func(*Cron)
// WithContext overrides the context used by the Cron.
func WithContext(ctx context.Context) Option {
return func(c *Cron) {
c.ctx = ctx
}
}
// 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
}
}
// WithMiddleware specifies Middleware to apply to all jobs added to this cron.
func WithMiddleware(middlewares ...Middleware) Option {
return func(c *Cron) {
c.middlewares = middlewares
}
}
// WithLogger uses the provided logger.
func WithLogger(logger Logger) Option {
return func(c *Cron) {
c.logger = logger
}
}