-
Notifications
You must be signed in to change notification settings - Fork 1
/
cron_option.go
46 lines (39 loc) · 1.02 KB
/
cron_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
package dcron
import (
"context"
"time"
)
// CronOption represents a modification to the default behavior of a Cron.
type CronOption func(c *Cron)
// WithKey overrides the key of the cron.
func WithKey(key string) CronOption {
return func(c *Cron) {
c.key = key
}
}
// WithHostname overrides the hostname of the cron instance.
func WithHostname(hostname string) CronOption {
return func(c *Cron) {
c.hostname = hostname
}
}
// WithAtomic uses the provided Atomic.
func WithAtomic(atomic Atomic) CronOption {
return func(c *Cron) {
c.atomic = atomic
}
}
// WithLocation overrides the timezone of the cron instance.
func WithLocation(loc *time.Location) CronOption {
return func(c *Cron) {
c.location = loc
}
}
// WithContext sets the root context of the cron instance.
// It will be used as the parent context of all tasks,
// and when the context is done, the cron will be stopped.
func WithContext(ctx context.Context) CronOption {
return func(c *Cron) {
c.context, c.contextCancel = context.WithCancel(ctx)
}
}