blockio

package
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package blockio provides CUE-validated YAML import/export for scheduling blocks, plus first-run bootstrap of a static scheduler file into the block store (see Bootstrap in bootstrap.go).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bootstrap

func Bootstrap(ctx context.Context, s *store.Store, path string, logger *slog.Logger) (int, error)

Bootstrap performs first-run import of a static scheduler YAML file into the block store.

Behavior:

  • If the store already has one or more blocks, Bootstrap is a no-op and returns (0, nil): the store is the source of truth once it has been populated, and a static file must never silently re-seed or duplicate data on every restart.
  • If the store is empty but path does not exist, Bootstrap is a no-op and returns (0, nil): there is nothing to import.
  • If the store is empty and path exists, Bootstrap parses and validates the file (via ParseYAML) and creates one BlockRecord per block, with a generated UUID as the ID, the block's Name, and Enabled set to true. It returns the number of blocks imported.
  • If the file exists but fails to parse or validate, Bootstrap returns an error and imports nothing: validation happens on the whole file before any block is written, so a bad file can never leave the store half-imported.

func ParseYAML

func ParseYAML(data []byte) ([]scheduler.Block, error)

ParseYAML validates YAML data against the CUE scheduler schema and strictly decodes it into scheduling blocks. Decoding is strict: unknown fields anywhere in the document are rejected rather than silently ignored.

CUE validation runs on the RAW input bytes, before the Go-struct decode -- not on a re-render of the decoded structs (what ValidateBlocks does, and what an earlier version of this function called). The ordering matters for CUE's `*default` semantics: a default applies only to an ABSENT field, and decoding into a Go struct first turns an omitted `type:` into an explicit `""`, which then fails #Block's `"filter" | "series" | *"filter"` disjunction on the re-render even though the original file was valid. Validating the original bytes lets a genuinely-omitted field stay absent, so the default applies exactly as the schema declares; the decode below then mirrors that default into the struct (Type "" -> "filter"). An EXPLICIT `type: ""` in the file still fails the disjunction, as it should.

ParseYAML also rejects blocks that share a name. This lives here rather than in the CUE schema or the store: CUE validates each block against #Block independently and has no notion of "list of blocks with unique names," so two same-named blocks in one file would otherwise sail through validation cleanly. Catching it here -- before any block from this file is written anywhere -- protects every YAML-driven import path (Bootstrap, POST /blocks/import) uniformly: a duplicate never gets far enough to hit store.ErrConflict partway through a batch of writes.

func RenderYAML

func RenderYAML(blocks []scheduler.Block) ([]byte, error)

RenderYAML renders blocks as YAML, wrapped in the scheduler.Config envelope used by scheduler files. Because it marshals a typed struct (scheduler.Config) rather than a map, field order is stable across calls: it always follows the struct's declared field order, not map iteration order.

func ValidateBlocks

func ValidateBlocks(blocks []scheduler.Block) error

ValidateBlocks validates blocks against the scheduler CUE schema. It renders the blocks to YAML (via RenderYAML) and runs the result through cueconfig's scheduler validator, wrapping any resulting CUE error.

func ValidateSharedShowAgreement added in v0.3.0

func ValidateSharedShowAgreement(blocks []scheduler.Block) error

ValidateSharedShowAgreement rejects a set of co-active blocks in which the same show carries contradictory completion policies. Series state is keyed by show title and shared across every block that schedules the show -- completion handling included -- so two blocks giving one show different policies fight over that shared state (whichever block plans latest re-applies its own policy: a show one block disabled can come back active when the other completes it, or one block's max_runs cap can globally disable a show another block asked to restart forever). The policy compared is the pair (on_complete, max_runs) -- max_runs only participates when the action is "restart", the only case the engine reads it (see markSeriesCompleted). Like duplicateBlockNames, this is a cross-block rule CUE cannot express (#Block validates each block independently), so it lives here and is shared by every write path: ParseYAML (Bootstrap, POST /blocks/import) checks the file/batch internally, and blocks CRUD (internal/api) checks an incoming spec against the store's enabled blocks. An empty on_complete means the CUE default, "continue".

Types

This section is empty.

Jump to

Keyboard shortcuts

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