From f7a1e92e82605f220ed6c1deddae58989f5166b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 25 Jun 2024 12:24:30 +0200 Subject: [PATCH] Manager: fix panic on task timeout Fix an issue where a timed-out task would cause a panic, as it wasn't fetching its Job UUID. I see this as working around a limitation of GORM, which should get replaced with sqlc soon-ish anyway. --- internal/manager/persistence/timeout.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/manager/persistence/timeout.go b/internal/manager/persistence/timeout.go index fc2b19dd..ad2d074d 100644 --- a/internal/manager/persistence/timeout.go +++ b/internal/manager/persistence/timeout.go @@ -37,6 +37,15 @@ func (db *DB) FetchTimedOutTasks(ctx context.Context, untouchedSince time.Time) if tx.Error != nil { return nil, taskError(tx.Error, "finding timed out tasks (untouched since %s)", untouchedSince.String()) } + + // GORM apparently doesn't call the task's AfterFind() function for the above query. + for _, task := range result { + err := task.AfterFind(tx) + if err != nil { + return nil, taskError(tx.Error, "finding the job & worker UUIDs for task %s", task.UUID) + } + } + return result, nil }