Skip to content

Commit

Permalink
Default grace period to 1s
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Sep 11, 2017
1 parent a0a0d1d commit 137d5c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions api/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func (r *RestartPolicy) Merge(rp *RestartPolicy) {
// CheckRestart describes if and when a task should be restarted based on
// failing health checks.
type CheckRestart struct {
Limit int `mapstructure:"limit"`
Grace time.Duration `mapstructure:"grace_period"`
IgnoreWarnings bool `mapstructure:"ignore_warnings"`
Limit int `mapstructure:"limit"`
Grace *time.Duration `mapstructure:"grace_period"`
IgnoreWarnings bool `mapstructure:"ignore_warnings"`
}

// The ServiceCheck data model represents the consul health check that
Expand All @@ -107,6 +107,14 @@ type ServiceCheck struct {
CheckRestart *CheckRestart `mapstructure:"check_restart"`
}

func (c *ServiceCheck) Canonicalize() {
if c.CheckRestart != nil {
if c.CheckRestart.Grace == nil {
c.CheckRestart.Grace = helper.TimeToPtr(1 * time.Second)
}
}
}

// The Service model represents a Consul service definition
type Service struct {
Id string
Expand All @@ -127,6 +135,10 @@ func (s *Service) Canonicalize(t *Task, tg *TaskGroup, job *Job) {
if s.AddressMode == "" {
s.AddressMode = "auto"
}

for _, c := range s.Checks {
c.Canonicalize()
}
}

// EphemeralDisk is an ephemeral disk object
Expand Down
4 changes: 2 additions & 2 deletions command/agent/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func ApiTaskToStructsTask(apiTask *api.Task, structsTask *structs.Task) {
if service.CheckRestart != nil {
structsTask.Services[i].CheckRestart = &structs.CheckRestart{
Limit: service.CheckRestart.Limit,
Grace: service.CheckRestart.Grace,
Grace: *service.CheckRestart.Grace,
IgnoreWarnings: service.CheckRestart.IgnoreWarnings,
}
}
Expand All @@ -714,7 +714,7 @@ func ApiTaskToStructsTask(apiTask *api.Task, structsTask *structs.Task) {
if check.CheckRestart != nil {
structsTask.Services[i].Checks[j].CheckRestart = &structs.CheckRestart{
Limit: check.CheckRestart.Limit,
Grace: check.CheckRestart.Grace,
Grace: *check.CheckRestart.Grace,
IgnoreWarnings: check.CheckRestart.IgnoreWarnings,
}
}
Expand Down

0 comments on commit 137d5c1

Please sign in to comment.