Documentation
¶
Overview ¶
Package store provides persistence for scheduling state.
Index ¶
- Variables
- type BlockRecord
- type Store
- func (s *Store) Backup(ctx context.Context, destPath string) error
- func (s *Store) CleanupScheduleHistory(ctx context.Context, window time.Duration) (int64, error)
- func (s *Store) Close() error
- func (s *Store) CountBlocks(ctx context.Context) (int64, error)
- func (s *Store) CreateBlock(ctx context.Context, rec *BlockRecord) error
- func (s *Store) DeleteBlock(ctx context.Context, id string) error
- func (s *Store) ExportAllSeriesStates(ctx context.Context) ([]scheduler.SeriesState, error)
- func (s *Store) GetBlock(ctx context.Context, id string) (*BlockRecord, error)
- func (s *Store) GetPersistedSeriesState(ctx context.Context, showTitle string) (*scheduler.SeriesState, error)
- func (s *Store) GetSeriesState(ctx context.Context, showTitle string) (*scheduler.SeriesState, error)
- func (s *Store) ImportSeriesStates(ctx context.Context, states []scheduler.SeriesState) error
- func (s *Store) ListBlocks(ctx context.Context) ([]BlockRecord, error)
- func (s *Store) ListScheduleHistory(ctx context.Context, since time.Time) ([]scheduler.ScheduleHistoryEntry, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) RecordScheduleHistory(ctx context.Context, entries []scheduler.ScheduleHistoryEntry) error
- func (s *Store) ResetSeriesState(ctx context.Context, showTitle string) error
- func (s *Store) SetSeriesState(ctx context.Context, showTitle string, season, episode int) error
- func (s *Store) UpdateBlock(ctx context.Context, rec *BlockRecord) error
- func (s *Store) UpdateSeriesState(ctx context.Context, state *scheduler.SeriesState) error
- func (s *Store) WasRecentlyScheduled(ctx context.Context, programID, channelID string, window time.Duration) (bool, error)
Constants ¶
This section is empty.
Variables ¶
var ErrConflict = errors.New("conflict")
ErrConflict indicates a uniqueness constraint was violated (e.g. duplicate name).
var ErrNotFound = errors.New("not found")
ErrNotFound indicates the requested record does not exist.
Functions ¶
This section is empty.
Types ¶
type BlockRecord ¶
type BlockRecord struct {
ID string // uuid string
Name string // unique
Enabled bool
Spec scheduler.Block // full block definition
CreatedAt time.Time
UpdatedAt time.Time
}
BlockRecord is the persisted representation of a scheduling block. Blocks are the API-editable source of truth for scheduling, replacing the static blocks previously defined in scheduler.yaml.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements the persistence layer for Schedularr.
func New ¶
New creates a new Store instance connected to the specified SQLite database. dsn is augmented with sqliteDSNParams -- see its doc comment.
func (*Store) Backup ¶
Backup creates a safe backup of the database to the specified path using VACUUM INTO.
func (*Store) CleanupScheduleHistory ¶
CleanupScheduleHistory removes schedule history entries older than the window.
func (*Store) CountBlocks ¶
CountBlocks returns the total number of blocks.
func (*Store) CreateBlock ¶
func (s *Store) CreateBlock(ctx context.Context, rec *BlockRecord) error
CreateBlock inserts a new block, setting CreatedAt/UpdatedAt. Returns ErrConflict if a block with the same name already exists.
func (*Store) DeleteBlock ¶
DeleteBlock removes a block by ID. Returns ErrNotFound if it does not exist.
func (*Store) ExportAllSeriesStates ¶
ExportAllSeriesStates exports all series states to a slice for backup/export.
func (*Store) GetBlock ¶
GetBlock retrieves a block by ID. Returns ErrNotFound if it does not exist.
func (*Store) GetPersistedSeriesState ¶
func (s *Store) GetPersistedSeriesState(ctx context.Context, showTitle string) (*scheduler.SeriesState, error)
GetPersistedSeriesState retrieves the tracking state for a given show, returning ErrNotFound if no row is persisted for it. This is the existence-aware counterpart to GetSeriesState: GetSeriesState always succeeds with a fabricated S01E01 default for an untracked show (useful for the scheduler engine, which needs a starting point regardless), which makes it unsuitable for callers that must map "unknown show" to a 404 -- currently the state API's PatchSeriesState handler (internal/api/state.go).
func (*Store) GetSeriesState ¶
func (s *Store) GetSeriesState(ctx context.Context, showTitle string) (*scheduler.SeriesState, error)
GetSeriesState retrieves the tracking state for a given show. If no state exists, it returns a default starting state (S01E01).
func (*Store) ImportSeriesStates ¶
ImportSeriesStates imports series states from a slice, replacing existing states.
func (*Store) ListBlocks ¶
func (s *Store) ListBlocks(ctx context.Context) ([]BlockRecord, error)
ListBlocks returns all blocks ordered by name.
func (*Store) ListScheduleHistory ¶
func (s *Store) ListScheduleHistory(ctx context.Context, since time.Time) ([]scheduler.ScheduleHistoryEntry, error)
ListScheduleHistory returns schedule history entries scheduled at or after since, ordered by scheduled_at DESC (most recent first). This backs the GET /history API endpoint (internal/api/history.go), which maps a caller-supplied days window to since = now - days.
func (*Store) Ping ¶
Ping verifies the database connection is live by executing a trivial `SELECT 1` round-trip, rather than sql.DB's own PingContext (which some drivers implement as a no-op connection check rather than an actual query). Used by the API server's /readyz endpoint (internal/api/router.go) to report readiness -- distinct from process liveness, which /healthz reports without touching the store at all.
func (*Store) RecordScheduleHistory ¶
func (s *Store) RecordScheduleHistory(ctx context.Context, entries []scheduler.ScheduleHistoryEntry) error
RecordScheduleHistory persists schedule history entries for future filtering.
func (*Store) ResetSeriesState ¶
ResetSeriesState resets a series to its starting state (S01E01, not completed).
func (*Store) SetSeriesState ¶
SetSeriesState sets a series to a specific season and episode. If the series doesn't exist, it creates a new entry.
func (*Store) UpdateBlock ¶
func (s *Store) UpdateBlock(ctx context.Context, rec *BlockRecord) error
UpdateBlock updates an existing block's fields and bumps UpdatedAt. Returns ErrNotFound if no block with the given ID exists, or ErrConflict if the update would violate the unique name constraint.
func (*Store) UpdateSeriesState ¶
UpdateSeriesState updates or inserts the tracking state for a show.