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 {
|
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)
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user