Worker: simplify "context done" checks
This commit is contained in:
parent
d98dbaa333
commit
e9212de196
@ -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 {
|
||||
// Check whether the context is closed before doing anything.
|
||||
select {
|
||||
default:
|
||||
case <-ctx.Done():
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
return l.buffer.SendTaskUpdate(ctx, taskID, update)
|
||||
}
|
||||
|
@ -59,13 +59,11 @@ func (te *TaskExecutor) Run(ctx context.Context, task api.AssignedTask) error {
|
||||
}
|
||||
|
||||
for _, cmd := range task.Commands {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
if ctx.Err() != nil {
|
||||
// Shutdown does not mean task failure; cleanly shutting down will hand
|
||||
// back the task for requeueing on the Manager.
|
||||
logger.Warn().Msg("task execution aborted due to context shutdown")
|
||||
return nil
|
||||
default:
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
runErr := te.cmdRunner.Run(ctx, task.Uuid, cmd)
|
||||
|
Loading…
Reference in New Issue
Block a user