From 09902d201c540787dce792b009e9432de0a78a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 10 Jun 2022 14:50:53 +0200 Subject: [PATCH] Manager: fix task timeout check logging of assigned workers The task's worker wasn't fetched from the database, always causing "unknown worker" messages in the task log. --- internal/manager/persistence/timeout.go | 7 +++++++ internal/manager/persistence/timeout_test.go | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/manager/persistence/timeout.go b/internal/manager/persistence/timeout.go index fbf1d075..d1e96243 100644 --- a/internal/manager/persistence/timeout.go +++ b/internal/manager/persistence/timeout.go @@ -11,11 +11,18 @@ import ( // This file contains functions for dealing with task/worker timeouts. Not database timeouts. +// FetchTimedOutTasks returns a slice of tasks that have timed out. +// +// In order to time out, a task must be in status `active` and not touched by a +// Worker since `untouchedSince`. +// +// The returned tasks also have their `Job` and `Worker` fields set. func (db *DB) FetchTimedOutTasks(ctx context.Context, untouchedSince time.Time) ([]*Task, error) { result := []*Task{} tx := db.gormDB.WithContext(ctx). Model(&Task{}). Joins("Job"). + Joins("Worker"). Where("tasks.status = ?", api.TaskStatusActive). Where("tasks.last_touched_at <= ?", untouchedSince). Scan(&result) diff --git a/internal/manager/persistence/timeout_test.go b/internal/manager/persistence/timeout_test.go index b9dfa9de..6dcc2051 100644 --- a/internal/manager/persistence/timeout_test.go +++ b/internal/manager/persistence/timeout_test.go @@ -46,6 +46,7 @@ func TestFetchTimedOutTasks(t *testing.T) { // Other fields will be different, like the 'UpdatedAt' field -- this just // tests that the expected task is returned. assert.Equal(t, task.UUID, timedout[0].UUID) - assert.Equal(t, job, task.Job, "the job should be included in the result as well") + assert.Equal(t, job, timedout[0].Job, "the job should be included in the result as well") + assert.Equal(t, w, timedout[0].Worker, "the worker should be included in the result as well") } }