Documentation
¶
Overview ¶
Package wavescheduler provides a background worker for scheduling queued runs within waves.
The scheduler continuously monitors waves and starts execution for queued runs.
State transitions:
- Wave: Started → Finished/Cancelled (terminal)
- Run: Queued → Running → Success/Fail/Cancelled (terminal)
The scheduler focuses on per-wave processing without cross-wave FIFO ordering.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNilRunStarter = errors.New("wavescheduler: run starter is required")
ErrNilRunStarter is returned when New is called with a nil RunStarter.
var ErrNilStore = errors.New("wavescheduler: store is required")
ErrNilStore is returned when New is called with a nil Store.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Store is the database store for querying waves and runs.
Store store.Store
// RunStarter handles the actual execution start logic.
RunStarter RunStarter
// Interval is how often the scheduler checks for queued runs. Default: 5 seconds.
Interval time.Duration
// Logger is used for structured logging. If nil, a default logger is used.
Logger *slog.Logger
}
Options configures the wave scheduler.
type RunStarter ¶
type RunStarter interface {
// StartQueuedRuns starts execution for all queued runs in a wave.
// Returns StartQueuedRunsResult with counts of started, already done, and queued runs.
StartQueuedRuns(ctx context.Context, waveID types.WaveID) (StartQueuedRunsResult, error)
}
RunStarter is the interface for starting execution of queued runs. Implemented by handlers.WaveRunStarter to decouple scheduler from HTTP layer.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler is a background task that processes queued runs within waves. It implements the scheduler.Task interface for integration with the server's task scheduler.
func New ¶
New constructs a new wave scheduler. Returns ErrNilStore if opts.Store is nil, or ErrNilRunStarter if opts.RunStarter is nil.
func (*Scheduler) Run ¶
Run executes one cycle of the wave scheduler.
The scheduler loop: 1. Query for waves with queued runs (ListWavesWithQueuedRuns) 2. For each wave, start execution for queued runs via RunStarter 3. Track and log progress
Errors from individual wave processing are logged but don't stop the scheduler.
type StartQueuedRunsResult ¶
type StartQueuedRunsResult struct {
// Started is the number of runs that were successfully started in this call.
Started int
// AlreadyDone is the number of runs already in a terminal state.
AlreadyDone int
// Pending is the number of runs still queued after this call.
Pending int
}
StartQueuedRunsResult contains the result of starting queued runs in a wave. This type is defined here to avoid circular imports with the handlers package. It mirrors handlers.StartQueuedRunsResult for interface compatibility.