From 2c79a10650f35fb74ae095136377a61ea13087fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 19 May 2022 14:59:25 +0200 Subject: [PATCH] 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. --- internal/worker/statemonitor.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/worker/statemonitor.go b/internal/worker/statemonitor.go index fc3632dd..2fa6adec 100644 --- a/internal/worker/statemonitor.go +++ b/internal/worker/statemonitor.go @@ -4,6 +4,7 @@ package worker import ( "context" + "errors" "net/http" "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 { resp, err := w.client.MayWorkerRunWithResponse(ctx, taskID) if err != nil { - log.Warn(). - Err(err). - Str("task", taskID). - Msg("error asking Manager may-I-keep-running task") + if errors.Is(err, context.Canceled) { + log.Debug(). + Str("task", taskID). + 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} }