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 ¶
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 ¶
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 ¶
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 ¶
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.
Types ¶
This section is empty.