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:
parent
734982ffbc
commit
09902d201c
@ -11,11 +11,18 @@ import (
|
|||||||
|
|
||||||
// This file contains functions for dealing with task/worker timeouts. Not database timeouts.
|
// 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) {
|
func (db *DB) FetchTimedOutTasks(ctx context.Context, untouchedSince time.Time) ([]*Task, error) {
|
||||||
result := []*Task{}
|
result := []*Task{}
|
||||||
tx := db.gormDB.WithContext(ctx).
|
tx := db.gormDB.WithContext(ctx).
|
||||||
Model(&Task{}).
|
Model(&Task{}).
|
||||||
Joins("Job").
|
Joins("Job").
|
||||||
|
Joins("Worker").
|
||||||
Where("tasks.status = ?", api.TaskStatusActive).
|
Where("tasks.status = ?", api.TaskStatusActive).
|
||||||
Where("tasks.last_touched_at <= ?", untouchedSince).
|
Where("tasks.last_touched_at <= ?", untouchedSince).
|
||||||
Scan(&result)
|
Scan(&result)
|
||||||
|
@ -46,6 +46,7 @@ func TestFetchTimedOutTasks(t *testing.T) {
|
|||||||
// Other fields will be different, like the 'UpdatedAt' field -- this just
|
// Other fields will be different, like the 'UpdatedAt' field -- this just
|
||||||
// tests that the expected task is returned.
|
// tests that the expected task is returned.
|
||||||
assert.Equal(t, task.UUID, timedout[0].UUID)
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user