Worker: simplify "context done" checks

This commit is contained in:
Sybren A. Stüvel 2022-04-09 16:57:39 +02:00
parent d98dbaa333
commit e9212de196
2 changed files with 3 additions and 9 deletions

View File

@ -109,12 +109,8 @@ func (l *Listener) OutputProduced(ctx context.Context, taskID string, outputLoca
} }
func (l *Listener) sendTaskUpdate(ctx context.Context, taskID string, update api.TaskUpdateJSONRequestBody) error { func (l *Listener) sendTaskUpdate(ctx context.Context, taskID string, update api.TaskUpdateJSONRequestBody) error {
// Check whether the context is closed before doing anything. if ctx.Err() != nil {
select {
default:
case <-ctx.Done():
return ctx.Err() return ctx.Err()
} }
return l.buffer.SendTaskUpdate(ctx, taskID, update) return l.buffer.SendTaskUpdate(ctx, taskID, update)
} }

View File

@ -59,13 +59,11 @@ func (te *TaskExecutor) Run(ctx context.Context, task api.AssignedTask) error {
} }
for _, cmd := range task.Commands { for _, cmd := range task.Commands {
select { if ctx.Err() != nil {
case <-ctx.Done():
// Shutdown does not mean task failure; cleanly shutting down will hand // Shutdown does not mean task failure; cleanly shutting down will hand
// back the task for requeueing on the Manager. // back the task for requeueing on the Manager.
logger.Warn().Msg("task execution aborted due to context shutdown") logger.Warn().Msg("task execution aborted due to context shutdown")
return nil return ctx.Err()
default:
} }
runErr := te.cmdRunner.Run(ctx, task.Uuid, cmd) runErr := te.cmdRunner.Run(ctx, task.Uuid, cmd)