Reuse default policy structs in api, and other code review feedback

This commit is contained in:
Preetha Appan
2018-01-31 16:33:00 -06:00
parent ee5b39071e
commit 15186170b4
3 changed files with 19 additions and 19 deletions

View File

@@ -340,17 +340,17 @@ func (g *TaskGroup) Canonicalize(job *Job) {
switch *job.Type {
case "service", "system":
defaultRestartPolicy = &RestartPolicy{
Delay: helper.TimeToPtr(15 * time.Second),
Attempts: helper.IntToPtr(2),
Interval: helper.TimeToPtr(1 * time.Minute),
Mode: helper.StringToPtr("delay"),
Delay: helper.TimeToPtr(structs.DefaultServiceJobRestartPolicy.Delay),
Attempts: helper.IntToPtr(structs.DefaultServiceJobRestartPolicy.Attempts),
Interval: helper.TimeToPtr(structs.DefaultServiceJobRestartPolicy.Interval),
Mode: helper.StringToPtr(structs.DefaultServiceJobRestartPolicy.Mode),
}
default:
defaultRestartPolicy = &RestartPolicy{
Delay: helper.TimeToPtr(15 * time.Second),
Attempts: helper.IntToPtr(15),
Interval: helper.TimeToPtr(7 * 24 * time.Hour),
Mode: helper.StringToPtr("delay"),
Delay: helper.TimeToPtr(structs.DefaultBatchJobRestartPolicy.Delay),
Attempts: helper.IntToPtr(structs.DefaultBatchJobRestartPolicy.Attempts),
Interval: helper.TimeToPtr(structs.DefaultBatchJobRestartPolicy.Interval),
Mode: helper.StringToPtr(structs.DefaultBatchJobRestartPolicy.Mode),
}
}

View File

@@ -2510,16 +2510,16 @@ func (d *DispatchPayloadConfig) Validate() error {
}
var (
defaultServiceJobRestartPolicy = RestartPolicy{
DefaultServiceJobRestartPolicy = RestartPolicy{
Delay: 15 * time.Second,
Attempts: 2,
Interval: 1 * time.Minute,
Interval: 30 * time.Minute,
Mode: RestartPolicyModeFail,
}
defaultBatchJobRestartPolicy = RestartPolicy{
DefaultBatchJobRestartPolicy = RestartPolicy{
Delay: 15 * time.Second,
Attempts: 15,
Interval: 7 * 24 * time.Hour,
Attempts: 3,
Interval: 24 * time.Hour,
Mode: RestartPolicyModeFail,
}
)
@@ -2604,10 +2604,10 @@ func (r *RestartPolicy) Validate() error {
func NewRestartPolicy(jobType string) *RestartPolicy {
switch jobType {
case JobTypeService, JobTypeSystem:
rp := defaultServiceJobRestartPolicy
rp := DefaultServiceJobRestartPolicy
return &rp
case JobTypeBatch:
rp := defaultBatchJobRestartPolicy
rp := DefaultBatchJobRestartPolicy
return &rp
}
return nil

View File

@@ -91,10 +91,10 @@ Below is the JSON representation of the job outputted by `$ nomad init`:
"Leader": false
}],
"RestartPolicy": {
"Interval": 300000000000,
"Attempts": 10,
"Delay": 25000000000,
"Mode": "delay"
"Interval": 1800000000000,
"Attempts": 2,
"Delay": 15000000000,
"Mode": "fail"
},
"EphemeralDisk": {
"SizeMB": 300