
Replace old used-to-be-GORM datastructures (#104305) with sqlc-generated structs. This also makes it possible to use more specific structs that are more taylored to the specific queries, increasing efficiency. This commit mostly deals with workers, including the sleep schedule and task scheduler. Functional changes are kept to a minimum, as the API still serves the same data. Because this work covers so much of Flamenco's code, it's been split up into different commits. Each commit brings Flamenco to a state where it compiles and unit tests pass. Only the result of the final commit has actually been tested properly. Ref: #104343
49 lines
2.0 KiB
Go
49 lines
2.0 KiB
Go
package timeout_checker
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/rs/zerolog"
|
|
"projects.blender.org/studio/flamenco/internal/manager/eventbus"
|
|
"projects.blender.org/studio/flamenco/internal/manager/persistence"
|
|
"projects.blender.org/studio/flamenco/internal/manager/persistence/sqlc"
|
|
"projects.blender.org/studio/flamenco/internal/manager/task_state_machine"
|
|
"projects.blender.org/studio/flamenco/pkg/api"
|
|
)
|
|
|
|
// Generate mock implementations of these interfaces.
|
|
//go:generate go run github.com/golang/mock/mockgen -destination mocks/interfaces_mock.gen.go -package mocks projects.blender.org/studio/flamenco/internal/manager/timeout_checker PersistenceService,TaskStateMachine,LogStorage,ChangeBroadcaster
|
|
|
|
type PersistenceService interface {
|
|
FetchTimedOutTasks(ctx context.Context, untouchedSince time.Time) ([]*persistence.Task, error)
|
|
FetchTimedOutWorkers(ctx context.Context, lastSeenBefore time.Time) ([]*persistence.Worker, error)
|
|
SaveWorker(ctx context.Context, w *sqlc.Worker) error
|
|
}
|
|
|
|
var _ PersistenceService = (*persistence.DB)(nil)
|
|
|
|
type TaskStateMachine interface {
|
|
// TaskStatusChange gives a Task a new status, and handles the resulting status changes on the job.
|
|
TaskStatusChange(ctx context.Context, task *persistence.Task, newStatus api.TaskStatus) error
|
|
RequeueActiveTasksOfWorker(ctx context.Context, worker *persistence.Worker, reason string) error
|
|
}
|
|
|
|
var _ TaskStateMachine = (*task_state_machine.StateMachine)(nil)
|
|
|
|
// LogStorage is used to append timeout messages to task logs.
|
|
type LogStorage interface {
|
|
WriteTimestamped(logger zerolog.Logger, jobID, taskID string, logText string) error
|
|
}
|
|
|
|
// TODO: Refactor the way worker status changes are handled, so that this
|
|
// service doens't need to broadcast its own worker updates.
|
|
type ChangeBroadcaster interface {
|
|
BroadcastWorkerUpdate(workerUpdate api.EventWorkerUpdate)
|
|
}
|
|
|
|
// ChangeBroadcaster should be a subset of eventbus.Broker.
|
|
var _ ChangeBroadcaster = (*eventbus.Broker)(nil)
|