fix: ensure that deferred tasks are run before ending job waitgroups

This commit is contained in:
Marc 2024-08-21 13:56:30 -04:00
parent 11c964e7be
commit e06b46e32d
Signed by: marc
GPG key ID: 048E042F22B5DC79

View file

@ -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)