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.
This commit is contained in:
Sybren A. Stüvel 2022-06-10 14:50:53 +02:00
parent 734982ffbc
commit 09902d201c
2 changed files with 9 additions and 1 deletions

@ -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)

@ -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")
}
}