fix: ensure that deferred tasks are called with defer
This commit is contained in:
parent
0bb9c3f127
commit
d8fb1b9a09
1 changed files with 6 additions and 5 deletions
|
@ -36,6 +36,8 @@ func (r *Runner) RunWorkflow(workflow workflow.Workflow) TaskTracker {
|
|||
|
||||
workflowContext := context.WithValue(context.Background(), "workflow", workflow)
|
||||
|
||||
defer r.deferred.RunAllDeferredTasks()
|
||||
|
||||
for _, group := range workflow.GetJobsAsGroups() {
|
||||
var groupWait sync.WaitGroup
|
||||
|
||||
|
@ -55,12 +57,13 @@ func (r *Runner) RunWorkflow(workflow workflow.Workflow) TaskTracker {
|
|||
// Runs a given job (provided a runner to run it on, its context, a task tracker for progress monitoring and
|
||||
// a WaitGroup to coordinate concurrent tasks) and updates the tracker with results.
|
||||
runJob := func(runner *Runner, jobContext context.Context, jobTracker *TaskTracker, jobWaitGroup *sync.WaitGroup) {
|
||||
containerName := fmt.Sprintf("runner-%s", jobTracker.TaskId)
|
||||
defer runner.deferred.RunDeferredTasksInScope(fmt.Sprintf("job-%s", containerName))
|
||||
defer jobWaitGroup.Done()
|
||||
|
||||
jobTracker.SetStatus("started")
|
||||
runnerImage := jobContext.Value("runnerImageUri").(string)
|
||||
|
||||
containerName := fmt.Sprintf("runner-%s", jobTracker.TaskId)
|
||||
|
||||
logger.Info("Using image %s (label: %s)", runnerImage, job.RunsOn)
|
||||
|
||||
if pullError := runner.Driver.Pull(runnerImage); pullError != nil {
|
||||
|
@ -82,7 +85,7 @@ func (r *Runner) RunWorkflow(workflow workflow.Workflow) TaskTracker {
|
|||
}
|
||||
|
||||
jobTracker.SetStatus("success")
|
||||
runner.deferred.RunDeferredTasksInScope(fmt.Sprintf("job-%s", containerName))
|
||||
|
||||
}
|
||||
|
||||
go runJob(r, jobContext, jobTracker, &groupWait)
|
||||
|
@ -91,8 +94,6 @@ func (r *Runner) RunWorkflow(workflow workflow.Workflow) TaskTracker {
|
|||
groupWait.Wait()
|
||||
}
|
||||
|
||||
r.deferred.RunAllDeferredTasks()
|
||||
|
||||
return *rootTracker
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue