forked from gochore/dcron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron_option.go
39 lines (33 loc) · 904 Bytes
/
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
package dcron
import (
"context"
"time"
)
// CronOption represents a modification to the default behavior of a Cron.
type CronOption func(c *Cron)
// WithHostname overrides the hostname of the cron instance.
func WithHostname(hostname string) CronOption {
return func(c *Cron) {
c.hostname = hostname
}
}
// WithLock uses the provided Lock.
func WithLock(lock Lock) CronOption {
return func(c *Cron) {
c.lock = lock
}
}
// 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)
}
}