diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 8e08892..ccfa76f 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -42,8 +42,6 @@ func (r *Runner) RunWorkflow(workflow workflow.Workflow) TaskTracker { var groupWait sync.WaitGroup for _, job := range group { - groupWait.Add(1) - jobTracker := NewTaskTracker(rootTracker) runnerImage, defined := r.Labels[job.RunsOn] if !defined { @@ -54,6 +52,7 @@ func (r *Runner) RunWorkflow(workflow workflow.Workflow) TaskTracker { jobContext := context.WithValue(workflowContext, "currentJob", job) jobContext = context.WithValue(jobContext, "runnerImageUri", runnerImage) + groupWait.Add(1) go r.runJob(jobContext, jobTracker, &groupWait) } @@ -69,8 +68,9 @@ func (r *Runner) RunWorkflow(workflow workflow.Workflow) TaskTracker { func (r Runner) runJob(jobContext context.Context, jobTracker *TaskTracker, jobWaitGroup *sync.WaitGroup) { job := jobContext.Value("currentJob").(workflow.Job) containerName := fmt.Sprintf("runner-%s", jobTracker.TaskId) - defer r.deferred.RunDeferredTasksInScope(fmt.Sprintf("job-%s", containerName)) + defer jobWaitGroup.Done() + defer r.deferred.RunDeferredTasksInScope(fmt.Sprintf("job-%s", containerName)) jobTracker.SetStatus("started") runnerImage := jobContext.Value("runnerImageUri").(string)