Documentation
¶
Overview ¶
Package schedule evaluates whether the daemon should be active at a given instant, combining the configured weekly windows with any manual override.
Index ¶
- func Active(cfg config.Config, t time.Time) bool
- func DesiredActive(cfg config.Config, ov Override, t time.Time) bool
- func NextChange(cfg config.Config, ov Override, t time.Time) (when time.Time, toActive bool, ok bool)
- func SaveOverride(path string, o Override) error
- type Override
- type OverrideMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Active ¶
Active reports whether the configured schedule (ignoring overrides) is active at time t. The instant is evaluated in the config's timezone.
func DesiredActive ¶
DesiredActive applies the override on top of the schedule and returns the effective desired state at time t. An expired override is ignored.
func NextChange ¶
func NextChange(cfg config.Config, ov Override, t time.Time) (when time.Time, toActive bool, ok bool)
NextChange scans forward from t (up to ~14 days) and returns the next instant at which DesiredActive flips, plus the state it flips to. ok is false if no change is found within the horizon (e.g. an indefinite override or 24/7).
func SaveOverride ¶
SaveOverride atomically writes the override to path.
Types ¶
type Override ¶
type Override struct {
Mode OverrideMode `json:"mode"`
Until *time.Time `json:"until,omitempty"`
SetAt time.Time `json:"set_at"`
}
Override is the persisted manual override. A nil Until is indefinite.
func LoadOverride ¶
LoadOverride reads override.json. A missing file yields a zero (None) override and no error.
func (Override) EffectiveMode ¶
func (o Override) EffectiveMode(t time.Time) OverrideMode
EffectiveMode returns the override mode in force at time t, treating an expired (Until <= t) override as OverrideNone.
type OverrideMode ¶
type OverrideMode string
OverrideMode is a manual override of the schedule.
const ( // OverrideNone means "follow the schedule". OverrideNone OverrideMode = "" // OverrideOn forces the daemon active. OverrideOn OverrideMode = "on" // OverrideOff forces the daemon inactive. OverrideOff OverrideMode = "off" )