From 162f75e834c723f2c303b60b9c49d2f954faf53a Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Mon, 22 Jan 2018 19:58:23 -0600 Subject: [PATCH] Address code review comments --- api/allocations.go | 4 ++-- api/tasks.go | 2 +- api/tasks_test.go | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/api/allocations.go b/api/allocations.go index 68e2e8f6f..36cbeb988 100644 --- a/api/allocations.go +++ b/api/allocations.go @@ -92,12 +92,12 @@ type Allocation struct { DeploymentStatus *AllocDeploymentStatus PreviousAllocation string NextAllocation string + RescheduleTracker *RescheduleTracker CreateIndex uint64 ModifyIndex uint64 AllocModifyIndex uint64 CreateTime int64 ModifyTime int64 - RescheduleTracker *RescheduleTracker } // AllocationMetric is used to deserialize allocation metrics. @@ -132,11 +132,11 @@ type AllocationListStub struct { ClientDescription string TaskStates map[string]*TaskState DeploymentStatus *AllocDeploymentStatus + RescheduleTracker *RescheduleTracker CreateIndex uint64 ModifyIndex uint64 CreateTime int64 ModifyTime int64 - RescheduleTracker *RescheduleTracker } // AllocDeploymentStatus captures the status of the allocation as part of the diff --git a/api/tasks.go b/api/tasks.go index 283ad70d3..08600f412 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -321,7 +321,7 @@ func (g *TaskGroup) Canonicalize(job *Job) { jobReschedule := job.Reschedule.Copy() jobReschedule.Merge(g.ReschedulePolicy) g.ReschedulePolicy = jobReschedule - } else if jr && !job.Reschedule.Empty() { + } else if jr { jobReschedule := job.Reschedule.Copy() g.ReschedulePolicy = jobReschedule } diff --git a/api/tasks_test.go b/api/tasks_test.go index 7b2fab461..37c47d514 100644 --- a/api/tasks_test.go +++ b/api/tasks_test.go @@ -296,8 +296,8 @@ func TestTaskGroup_Canonicalize_ReschedulePolicy(t *testing.T) { }, taskReschedulePolicy: nil, expected: &ReschedulePolicy{ - Attempts: helper.IntToPtr(structs.DefaultBatchJobReschedulePolicy.Attempts), - Interval: helper.TimeToPtr(structs.DefaultBatchJobReschedulePolicy.Interval), + Attempts: helper.IntToPtr(0), + Interval: helper.TimeToPtr(0), }, }, { @@ -337,6 +337,19 @@ func TestTaskGroup_Canonicalize_ReschedulePolicy(t *testing.T) { Interval: helper.TimeToPtr(5 * time.Minute), }, }, + { + desc: "Override from group", + jobReschedulePolicy: &ReschedulePolicy{ + Attempts: helper.IntToPtr(1), + }, + taskReschedulePolicy: &ReschedulePolicy{ + Attempts: helper.IntToPtr(5), + }, + expected: &ReschedulePolicy{ + Attempts: helper.IntToPtr(5), + Interval: helper.TimeToPtr(structs.DefaultBatchJobReschedulePolicy.Interval), + }, + }, { desc: "Attempts from job, default interval", jobReschedulePolicy: &ReschedulePolicy{