wavescheduler

package
v0.1.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 6 Imported by: 0

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

View Source
var ErrNilRunStarter = errors.New("wavescheduler: run starter is required")

ErrNilRunStarter is returned when New is called with a nil RunStarter.

View Source
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

func New(opts Options) (*Scheduler, error)

New constructs a new wave scheduler. Returns ErrNilStore if opts.Store is nil, or ErrNilRunStarter if opts.RunStarter is nil.

func (*Scheduler) Interval

func (s *Scheduler) Interval() time.Duration

Interval returns how often the task should run.

func (*Scheduler) Name

func (s *Scheduler) Name() string

Name returns the task name for the scheduler.

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL