Skip to content

Commit

Permalink
Merge pull request agola-io#219 from sgotti/runservice_mark_not_runni…
Browse files Browse the repository at this point in the history
…ng_tasks_skipped_when_run_stop

runservice: mark not running tasks as skipped when run marked to stop
  • Loading branch information
sgotti authored Feb 27, 2020
2 parents 36062f5 + 2e41390 commit b3bf63f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
20 changes: 19 additions & 1 deletion internal/services/runservice/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
33 changes: 31 additions & 2 deletions internal/services/runservice/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
},
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b3bf63f

Please sign in to comment.