Files
archie/internal/infrastructure/configuration/scheduling.go
T
sam 9b2fb4a82c feat(configuration): report config keys no decode target consumed
decodeTOML discarded toml.DecodeFile's metadata, so a misspelled or
renamed key parsed, validated and silently did nothing. Document.UnknownKeys
now carries the dotted key paths a loaded file's decode targets left
undecoded.

One file feeds two decode targets (&doc.Config and &doc.Scheduling), so a
key legitimately owned by one shows up as undecoded in the other -- a key
is only reported when both leave it undecoded (unknownKeys intersects the
two sets), which is what keeps a valid [scheduling] block from being
misreported as unknown on every config that uses it.

YAML config sources are unchanged for now (no equivalent metadata hook in
the yaml decoder); this covers the TOML path, which is what
config.example.toml, every shipped deployments/*.toml profile, and
install.sh's generated config.toml all use.
2026-09-15 05:07:54 +10:00

75 lines
2.0 KiB
Go

package configuration
import (
"fmt"
"time"
"gopkg.in/yaml.v3"
)
// SchedulingInput is the external [scheduling] input document. It deliberately
// contains no runtime defaults or domain dependencies; application composition
// translates it into scheduling.EngineConfig.
type SchedulingInput struct {
Interval Duration `toml:"interval" yaml:"interval"`
MaxParallel int `toml:"max_parallel" yaml:"max_parallel"`
JobTimeout Duration `toml:"job_timeout" yaml:"job_timeout"`
EventsSink string `toml:"events_sink" yaml:"events_sink"`
}
// Duration is a textual duration at the configuration boundary.
type Duration time.Duration
func (d *Duration) UnmarshalText(text []byte) error {
value, err := time.ParseDuration(string(text))
if err != nil {
return err
}
*d = Duration(value)
return nil
}
func (d Duration) Std() time.Duration { return time.Duration(d) }
const (
EventsSinkBus = "bus"
EventsSinkNone = "none"
)
type schedulingDocument struct {
Scheduling SchedulingInput `toml:"scheduling" yaml:"scheduling"`
}
func decodeSchedulingFile(path string, target *SchedulingInput) error {
_, err := decodeSchedulingFileKeys(path, target)
return err
}
// decodeSchedulingFileKeys is decodeSchedulingFile plus the file's
// undecoded top-level keys under this target (see decodeConfigFileKeys).
func decodeSchedulingFileKeys(path string, target *SchedulingInput) ([]string, error) {
doc := schedulingDocument{Scheduling: *target}
keys, err := decodeConfigFileKeys(path, &doc)
if err != nil {
return nil, err
}
*target = doc.Scheduling
return keys, nil
}
func applySchedulingOverlay(target *SchedulingInput, overrides map[string]any) error {
if len(overrides) == 0 {
return nil
}
data, err := yaml.Marshal(overrides)
if err != nil {
return fmt.Errorf("%w: encoding scheduling overlay: %w", ErrUnreadable, err)
}
doc := schedulingDocument{Scheduling: *target}
if err := yaml.Unmarshal(data, &doc); err != nil {
return fmt.Errorf("%w: parsing scheduling overlay: %w", ErrUnreadable, err)
}
*target = doc.Scheduling
return nil
}