diff --git a/internal/runner/runner.go b/internal/runner/runner.go index b3e61cc..8506971 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -54,41 +54,7 @@ func (r *Runner) RunWorkflow(workflow workflow.Workflow) TaskTracker { jobContext := context.WithValue(workflowContext, "currentJob", job) jobContext = context.WithValue(jobContext, "runnerImageUri", runnerImage) - // 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) - - logger.Info("Using image %s (label: %s)", runnerImage, job.RunsOn) - - if pullError := runner.Driver.Pull(runnerImage); pullError != nil { - jobTracker.SetError(pullError) - - if !job.ContinueOnError { - jobTracker.SetStatus("failed") - return - } - - } - - if runError := runner.RunJobInContainer(runnerImage, containerName, jobContext); runError != nil { - jobTracker.SetError(runError) - if !job.ContinueOnError { - jobTracker.SetStatus("failed") - return - } - } - - jobTracker.SetStatus("success") - - } - - go runJob(r, jobContext, jobTracker, &groupWait) + go r.runJob(jobContext, jobTracker, &groupWait) } groupWait.Wait() @@ -97,6 +63,42 @@ func (r *Runner) RunWorkflow(workflow workflow.Workflow) TaskTracker { return *rootTracker } +// 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. + +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() + + jobTracker.SetStatus("started") + runnerImage := jobContext.Value("runnerImageUri").(string) + + logger.Info("Using image %s (label: %s)", runnerImage, job.RunsOn) + + if pullError := r.Driver.Pull(runnerImage); pullError != nil { + jobTracker.SetError(pullError) + + if !job.ContinueOnError { + jobTracker.SetStatus("failed") + return + } + + } + + if runError := r.RunJobInContainer(runnerImage, containerName, jobContext); runError != nil { + jobTracker.SetError(runError) + if !job.ContinueOnError { + jobTracker.SetStatus("failed") + return + } + } + + jobTracker.SetStatus("success") + +} + // Executes a command within the given container. // // If the command raises an error while in the container or fails to run