fix restart policy for system jobs with no lifecycle

This commit is contained in:
Jasmine Dahilig
2020-02-12 07:24:03 -08:00
committed by Mahmood Ali
parent 43fab7d46d
commit dcd317745d
2 changed files with 28 additions and 1 deletions

View File

@@ -21,7 +21,7 @@ const (
)
func NewRestartTracker(policy *structs.RestartPolicy, jobType string, tlc *structs.TaskLifecycleConfig) *RestartTracker {
onSuccess := jobType == structs.JobTypeService
onSuccess := jobType != structs.JobTypeBatch
if tlc != nil && tlc.Hook == structs.TaskLifecycleHookPrestart {
onSuccess = tlc.BlockUntil != structs.TaskLifecycleBlockUntilCompleted
}

View File

@@ -210,6 +210,13 @@ func TestClient_RestartTracker_Lifecycle(t *testing.T) {
shouldRestartOnSuccess bool
shouldRestartOnFailure bool
}{
{
name: "system job no lifecycle",
taskLifecycleConfig: nil,
jobType: structs.JobTypeSystem,
shouldRestartOnSuccess: true,
shouldRestartOnFailure: true,
},
{
name: "service job no lifecycle",
taskLifecycleConfig: nil,
@@ -224,6 +231,26 @@ func TestClient_RestartTracker_Lifecycle(t *testing.T) {
shouldRestartOnSuccess: false,
shouldRestartOnFailure: true,
},
{
name: "system job w/ lifecycle completed",
taskLifecycleConfig: &structs.TaskLifecycleConfig{
Hook: structs.TaskLifecycleHookPrestart,
BlockUntil: structs.TaskLifecycleBlockUntilCompleted,
},
jobType: structs.JobTypeSystem,
shouldRestartOnSuccess: false,
shouldRestartOnFailure: true,
},
{
name: "system job w/ lifecycle running",
taskLifecycleConfig: &structs.TaskLifecycleConfig{
Hook: structs.TaskLifecycleHookPrestart,
BlockUntil: structs.TaskLifecycleBlockUntilRunning,
},
jobType: structs.JobTypeSystem,
shouldRestartOnSuccess: true,
shouldRestartOnFailure: true,
},
{
name: "service job w/ lifecycle completed",
taskLifecycleConfig: &structs.TaskLifecycleConfig{