From 22f56890c18a36afc8d044e8479bd4b409676ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 9 Feb 2023 11:46:29 +0100 Subject: [PATCH] Small fix for sleep schedule of soft-deleted workers There were `ErrWorkerNotFound` errors in different packages, which got mixed up. Now there's only one. --- internal/manager/sleep_scheduler/sleep_scheduler.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/manager/sleep_scheduler/sleep_scheduler.go b/internal/manager/sleep_scheduler/sleep_scheduler.go index 58223564..d67028c0 100644 --- a/internal/manager/sleep_scheduler/sleep_scheduler.go +++ b/internal/manager/sleep_scheduler/sleep_scheduler.go @@ -23,11 +23,6 @@ var skipWorkersInStatus = map[api.WorkerStatus]bool{ api.WorkerStatusError: true, } -// ErrWorkerNotFound is returned when the owning Worker of a sleep schedule cannot be found. -// This can happen when a Worker has been soft-deleted, which doesn't -// automatically trigger the deletion of the foreign key constraints. -var ErrWorkerNotFound = errors.New("worker not found") - // SleepScheduler manages wake/sleep cycles of Workers. type SleepScheduler struct { clock clock.Clock @@ -224,10 +219,13 @@ func (ss *SleepScheduler) checkSchedule(ctx context.Context, schedule *persisten switch { case errors.Is(ctx.Err(), context.Canceled): // Manager is shutting down, this is fine. - case errors.Is(err, ErrWorkerNotFound): + case errors.Is(err, persistence.ErrWorkerNotFound): // This schedule's worker cannot be found. That's fine, it could have been // soft-deleted (and thus foreign key constraints don't trigger deletion of // the sleep schedule). + log.Debug(). + Uint("worker", schedule.WorkerID). + Msg("sleep scheduler: sleep schedule's owning worker cannot be found; not applying the schedule") case err != nil: log.Error(). Err(err).