Files
archie/internal/infrastructure/configuration/scheduling.go
T

67 lines
1.7 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 {
doc := schedulingDocument{Scheduling: *target}
if err := decodeConfigFile(path, &doc); err != nil {
return err
}
*target = doc.Scheduling
return 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
}