mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 01:15:43 +03:00
Reuse default policy structs in api, and other code review feedback
This commit is contained in:
16
api/tasks.go
16
api/tasks.go
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user