maintenance

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: AGPL-3.0 Imports: 11 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 maintenance computes when maintenance windows are active (FA-MNT-01). It is pure: no I/O, no clock reads; callers pass the instants they ask about.

A schedule is either "once", a fixed interval [StartsMs, EndsMs), or "recurring": a 5-field cron expression evaluated in a time zone. Every cron match starts a window that lasts DurationMinutes of elapsed time.

DST rules for recurring schedules:

  • Cron fields are matched against the local wall-clock time in the zone.
  • A local start time that does not exist (spring-forward gap) starts at the instant the clock jumps forward. In Europe/Berlin, "30 2 * * *" on 2026-03-29 starts at 01:00 UTC (03:00 CEST).
  • A local start time that occurs twice (fall-back overlap) starts once, at its first occurrence. In Europe/Berlin, "30 2 * * *" on 2026-10-25 starts at 00:30 UTC (02:30 CEST); the second occurrence at 01:30 UTC starts nothing.
  • Durations are elapsed real time. A window crossing a transition lasts DurationMinutes of real time, not of wall-clock time.

StartsMs and EndsMs bound recurring starts (0 = unbounded). They do not cut the end of an occurrence that started within the bounds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Applier

type Applier interface {
	Apply(ctx context.Context, cmd *pb.Command) (cluster.ApplyResult, error)
}

Applier proposes Raft commands. *cluster.Node satisfies it.

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller keeps the MAINTENANCE status of monitors in line with the maintenance windows (FA-MNT-02). Every node caches the compiled windows so that the aggregator can ask InMaintenance; only the leader proposes status changes.

func NewController

func NewController(opts ControllerOptions) *Controller

NewController creates a Controller with defaults applied to opts.

func (*Controller) InMaintenance

func (c *Controller) InMaintenance(m store.Monitor, at time.Time) bool

InMaintenance reports whether an active window applies to m at the instant at. It uses the windows cached by Refresh and is safe for concurrent use.

func (*Controller) Reconcile

func (c *Controller) Reconcile(ctx context.Context) error

Reconcile proposes the status changes that bring every monitor (except the paused ones) in line with the cached windows at the current time: monitors inside a window enter MAINTENANCE, monitors whose last window has ended leave it. Only the leader may call it.

func (*Controller) Refresh

func (c *Controller) Refresh(ctx context.Context) error

Refresh loads the maintenance windows of all tenants, keeps the active ones and compiles their schedules. Invalid schedules are skipped with a warning. On error the previous set stays in effect. An invalid window is reported once per revision, as it is refreshed every interval.

func (*Controller) Run

func (c *Controller) Run(ctx context.Context)

Run refreshes the cached windows and, on the leader, reconciles the monitor states, immediately and then every Interval, until ctx ends.

type ControllerOptions

type ControllerOptions struct {
	State   store.State
	Cluster Applier
	// IsLeader reports whether this node may propose commands; only the leader reconciles.
	IsLeader func() bool
	Logger   *slog.Logger
	// Now is the clock used for the reconciliation (default time.Now).
	Now func() time.Time
	// Interval is the period of Refresh and Reconcile (default 15 s).
	Interval time.Duration
}

ControllerOptions configure a Controller. Zero values select the defaults, except for State, Cluster and IsLeader, which should be set.

type Cron

type Cron struct {
	// contains filtered or unexported fields
}

Cron is a parsed 5-field cron expression (minute hour day-of-month month day-of-week). Every field is stored as a bitset of its allowed values.

func ParseCron

func ParseCron(expr string) (*Cron, error)

ParseCron parses a standard 5-field cron expression or one of the macros @yearly, @annually, @monthly, @weekly, @daily, @midnight and @hourly. Fields support *, numbers, names (JAN-DEC, SUN-SAT, case-insensitive), ranges a-b, lists a,b, and steps */n and a-b/n. Day-of-week accepts 0-7, where 0 and 7 both mean Sunday.

func (*Cron) Matches

func (c *Cron) Matches(t time.Time) bool

Matches reports whether the wall-clock minute of t, read in t's location, matches the expression.

type Schedule

type Schedule struct {
	// contains filtered or unexported fields
}

Schedule is a validated, compiled maintenance schedule.

func Compile

func Compile(s store.MaintenanceSchedule) (*Schedule, error)

Compile validates s and returns its compiled form.

For "once" the interval must satisfy StartsMs < EndsMs and Cron must be empty. For "recurring" the cron expression must parse, DurationMinutes must be in 1..10080, Timezone must load (empty means UTC), and, when both bounds are set, StartsMs < EndsMs.

func (*Schedule) NextStart

func (s *Schedule) NextStart(after time.Time) (time.Time, bool)

NextStart returns the first window start strictly after after. It searches at most five years ahead and returns false if there is none. The returned time is UTC.

func (*Schedule) Occurrence

func (s *Schedule) Occurrence(at time.Time) (start, end time.Time, ok bool)

Occurrence returns the window active at at (start <= at < end). When recurring windows overlap, it returns the one with the latest end. The returned times are UTC.

Jump to

Keyboard shortcuts

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