/
job_config.go
63 lines (55 loc) · 1.79 KB
/
job_config.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
60
61
62
63
package jobkit
import (
"time"
"github.com/blend/go-sdk/cron"
)
// JobConfig is something you can use to give your jobs some knobs to turn
// from configuration.
// You can use this job config by embedding it into your larger job config struct.
type JobConfig struct {
cron.JobConfig `yaml:",inline"`
ShellActionConfig `yaml:",inline"`
Name string `yaml:"name"`
Schedule string `yaml:"schedule"`
HistoryPath string `yaml:"historyPath"`
HistoryDisabled *bool `yaml:"historyDisabled"`
HistoryMaxAge *time.Duration `yaml:"historyMaxAge"`
HistoryMaxCount *int `yaml:"historyMaxCount"`
Parameters []Parameter `yaml:"parameters"`
Notifications JobNotificationsConfig `yaml:"notifications"`
}
// ScheduleOrDefault returns a value or a default.
func (jc JobConfig) ScheduleOrDefault() string {
if jc.Schedule != "" {
return jc.Schedule
}
return DefaultSchedule
}
// HistoryPathOrDefault returns a value or a default.
func (jc JobConfig) HistoryPathOrDefault() string {
if jc.HistoryPath != "" {
return jc.HistoryPath
}
return DefaultHistoryPath
}
// HistoryDisabledOrDefault returns a value or a default.
func (jc JobConfig) HistoryDisabledOrDefault() bool {
if jc.HistoryDisabled != nil {
return *jc.HistoryDisabled
}
return false
}
// HistoryMaxAgeOrDefault returns a value or a default.
func (jc JobConfig) HistoryMaxAgeOrDefault() time.Duration {
if jc.HistoryMaxAge != nil {
return *jc.HistoryMaxAge
}
return DefaultHistoryMaxAge
}
// HistoryMaxCountOrDefault returns a value or a default.
func (jc JobConfig) HistoryMaxCountOrDefault() int {
if jc.HistoryMaxCount != nil {
return *jc.HistoryMaxCount
}
return DefaultHistoryMaxCount
}