diff --git a/internal/services/runservice/scheduler.go b/internal/services/runservice/scheduler.go index 9816ea4..c1c28dd 100644 --- a/internal/services/runservice/scheduler.go +++ b/internal/services/runservice/scheduler.go @@ -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 diff --git a/internal/services/runservice/scheduler_test.go b/internal/services/runservice/scheduler_test.go index e3ea1a8..2d1164e 100644 --- a/internal/services/runservice/scheduler_test.go +++ b/internal/services/runservice/scheduler_test.go @@ -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 {