Worker: don't log error if may-i-keep-running is shut down

Don't log an error if a worker shutdown (indicated by the context closing)
interrupts a may-i-keep-running call. Instead, log at debug level and just
return "yes, keep running"; we want the Worker to stop the task because it
is shutting down, and not because the Manager told us so.
This commit is contained in:
Sybren A. Stüvel 2022-05-19 14:59:25 +02:00
parent 03a021e14f
commit 2c79a10650

View File

@ -4,6 +4,7 @@ package worker
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@ -43,10 +44,16 @@ func (w *Worker) queryManagerForStateChange(ctx context.Context) *api.WorkerStat
func (w *Worker) mayIKeepRunning(ctx context.Context, taskID string) api.MayKeepRunning { func (w *Worker) mayIKeepRunning(ctx context.Context, taskID string) api.MayKeepRunning {
resp, err := w.client.MayWorkerRunWithResponse(ctx, taskID) resp, err := w.client.MayWorkerRunWithResponse(ctx, taskID)
if err != nil { if err != nil {
log.Warn(). if errors.Is(err, context.Canceled) {
Err(err). log.Debug().
Str("task", taskID). Str("task", taskID).
Msg("error asking Manager may-I-keep-running task") Msg("may-I-keep-running query interrupted by shutdown")
} else {
log.Warn().
Err(err).
Str("task", taskID).
Msg("error asking Manager may-I-keep-running task")
}
return api.MayKeepRunning{MayKeepRunning: true} return api.MayKeepRunning{MayKeepRunning: true}
} }