Merge pull request #219 from sgotti/runservice_mark_not_running_tasks_skipped_when_run_stop

runservice: mark not running tasks as skipped when run marked to stop
This commit is contained in:
Simone Gotti 2020-02-27 09:34:27 +01:00 committed by GitHub
commit e8fdb8dfae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 3 deletions

View File

@ -103,6 +103,24 @@ func advanceRunTasks(ctx context.Context, curRun *types.Run, rc *types.RunConfig
// take a deepcopy of r so we do logic only on fixed status and not affeccted by current changes (due to random map iteration)
newRun := curRun.DeepCopy()
if newRun.Stop {
// if the run is set to stop, skip all not running tasks
for _, rt := range newRun.Tasks {
isScheduled := false
for _, et := range activeExecutorTasks {
if rt.ID == et.ID {
isScheduled = true
}
}
if isScheduled {
continue
}
if rt.Status == types.RunTaskStatusNotStarted {
rt.Status = types.RunTaskStatusSkipped
}
}
}
// handle root tasks
for _, rt := range newRun.Tasks {
if rt.Skip {
@ -473,7 +491,7 @@ func (s *Runservice) scheduleRun(ctx context.Context, r *types.Run, rc *types.Ru
return err
}
// if the run is set to stop, stop all tasks
// if the run is set to stop, stop all active tasks
if r.Stop {
for _, et := range activeExecutorTasks {
et.Spec.Stop = true

View File

@ -65,8 +65,9 @@ func TestAdvanceRunTasks(t *testing.T) {
Skip: false,
},
"task04": &types.RunConfigTask{
ID: "task04",
Name: "task04",
ID: "task04",
Name: "task04",
Depends: map[string]*types.RunConfigTaskDepend{},
Runtime: &types.Runtime{Type: types.RuntimeType("pod"),
Containers: []*types.Container{{Image: "image01"}},
},
@ -356,6 +357,34 @@ func TestAdvanceRunTasks(t *testing.T) {
return run
}(),
},
{
name: "skip all not started tasks when run is set to stop",
rc: func() *types.RunConfig {
rc := rc.DeepCopy()
return rc
}(),
r: func() *types.Run {
run := run.DeepCopy()
run.Tasks["task01"].Status = types.RunTaskStatusRunning
run.Tasks["task04"].Status = types.RunTaskStatusSuccess
run.Tasks["task03"].Status = types.RunTaskStatusCancelled
run.Stop = true
return run
}(),
activeExecutorTasks: []*types.ExecutorTask{
&types.ExecutorTask{ID: "task01"},
},
out: func() *types.Run {
run := run.DeepCopy()
run.Stop = true
run.Tasks["task01"].Status = types.RunTaskStatusRunning
run.Tasks["task02"].Status = types.RunTaskStatusSkipped
run.Tasks["task03"].Status = types.RunTaskStatusCancelled
run.Tasks["task04"].Status = types.RunTaskStatusSuccess
run.Tasks["task05"].Status = types.RunTaskStatusSkipped
return run
}(),
},
}
for _, tt := range tests {