Skip to content

Commit

Permalink
executor: refactoring to avoid locking during setupTask
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandro-sorint committed Jun 8, 2022
1 parent ae347ab commit 521ebd2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/services/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,9 @@ func (e *Executor) executeTask(rt *runningTask) {
e.log.Err(err).Send()
}

rt.Unlock()
if err := e.setupTask(ctx, rt); err != nil {
rt.Lock()
e.log.Err(err).Send()
et.Status.Phase = types.ExecutorTaskPhaseFailed
et.Status.EndTime = util.TimeP(time.Now())
Expand All @@ -767,10 +769,10 @@ func (e *Executor) executeTask(rt *runningTask) {
if err := e.sendExecutorTaskStatus(ctx, et); err != nil {
e.log.Err(err).Send()
}
rt.Unlock()
return
}

rt.Lock()
et.Status.SetupStep.Phase = types.ExecutorTaskPhaseSuccess
et.Status.SetupStep.EndTime = util.TimeP(time.Now())
if err := e.sendExecutorTaskStatus(ctx, et); err != nil {
Expand Down Expand Up @@ -905,6 +907,7 @@ func (e *Executor) setupTask(ctx context.Context, rt *runningTask) error {
func (e *Executor) executeTaskSteps(ctx context.Context, rt *runningTask, pod driver.Pod) (int, error) {
for i, step := range rt.et.Spec.Steps {
rt.Lock()

rt.et.Status.Steps[i].Phase = types.ExecutorTaskPhaseRunning
rt.et.Status.Steps[i].StartTime = util.TimeP(time.Now())
if err := e.sendExecutorTaskStatus(ctx, rt.et); err != nil {
Expand Down Expand Up @@ -951,6 +954,7 @@ func (e *Executor) executeTaskSteps(ctx context.Context, rt *runningTask, pod dr
var serr error

rt.Lock()

rt.et.Status.Steps[i].EndTime = util.TimeP(time.Now())

rt.et.Status.Steps[i].Phase = types.ExecutorTaskPhaseSuccess
Expand Down Expand Up @@ -1071,6 +1075,7 @@ func (e *Executor) executorTasksStatusSenderLoop(ctx context.Context) {
}

rt.Lock()

if err := e.sendExecutorTaskStatus(ctx, rt.et); err != nil {
e.log.Err(err).Send()
rt.Unlock()
Expand Down

0 comments on commit 521ebd2

Please sign in to comment.