Sybren A. Stüvel ddced5a823 Transition from ex-GORM structs to sqlc structs (4/5)
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 deals with the worker sleep schedule.

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
2024-12-04 14:00:19 +01:00

37 lines
1.5 KiB
Go

package sleep_scheduler
// SPDX-License-Identifier: GPL-3.0-or-later
import (
"context"
"projects.blender.org/studio/flamenco/internal/manager/eventbus"
"projects.blender.org/studio/flamenco/internal/manager/persistence"
"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/sleep_scheduler PersistenceService,ChangeBroadcaster
type PersistenceService interface {
FetchWorkerSleepSchedule(ctx context.Context, workerUUID string) (*persistence.SleepSchedule, error)
SetWorkerSleepSchedule(ctx context.Context, workerUUID string, schedule *persistence.SleepSchedule) error
FetchSleepScheduleWorker(ctx context.Context, schedule persistence.SleepSchedule) (*persistence.Worker, error)
FetchSleepSchedulesToCheck(ctx context.Context) ([]persistence.SleepScheduleOwned, error)
SetWorkerSleepScheduleNextCheck(ctx context.Context, schedule persistence.SleepSchedule) error
SaveWorkerStatus(ctx context.Context, w *persistence.Worker) error
}
var _ PersistenceService = (*persistence.DB)(nil)
// 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)