-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
53 lines (45 loc) · 1.08 KB
/
conf.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
package cronjob
import (
"log"
"time"
)
// CronJobConf represents a function to configure the behaviour of cronjob.
type CronJobConf func(*CronJob)
// WithLogger overwrites the default logger.
func WithLogger(logger *log.Logger) CronJobConf {
return func(cj *CronJob) {
cj.logger = logger
}
}
// WithVerbose puts cronjob in verbose mode.
func WithVerbose() CronJobConf {
return func(cj *CronJob) {
cj.verbose = true
}
}
// WithLocation sets the location used by cronjob.
func WithLocation(loc *time.Location) CronJobConf {
return func(cj *CronJob) {
cj.location = loc
}
}
// JobConf represents a function to configure the behaviour of a job.
type JobConf func(*Job)
// WithRunOnStart makes the job run on start.
//
// if running: run when added.
//
// if not running: run when cronjob starts.
//
// note: the job will run with any previous configuration provided.
func WithRunOnStart() JobConf {
return func(j *Job) {
j.runOnStart = true
}
}
// WithChain sets the chains to run with the job.
func WithChain(chain Chain) JobConf {
return func(j *Job) {
j.chain = chain
}
}