Help us shape the future of Go! Take the 2026 Go Developer Survey

schedule

package
v1.97.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package schedule is what an agent reports of how often each set it writes gets a snapshot, and when a store counts a set late by that.

Index

Constants

View Source
const (
	Every    = "every"
	Cron     = "cron"
	Receiver = "receiver"
)

The kinds of plan a set's snapshots follow: an interval, a cron expression, or a receiver of a database's log, which commits only while the database writes.

View Source
const (
	ReportEvery = 24 * time.Hour
	SilentAfter = 48 * time.Hour
	StaleAfter  = 30 * 24 * time.Hour
)

An agent reports every ReportEvery. It is silent once its report is SilentAfter overdue, and what it reported expires StaleAfter after its last report.

Variables

View Source
var ErrInvalid = errors.New("invalid schedule")

ErrInvalid is an Expectation no plan makes.

Functions

func Grace

func Grace(gap time.Duration) time.Duration

Grace is how long past its longest gap a set may go without a snapshot: half the gap, and at least an hour.

Types

type Expectation

type Expectation struct {
	Set  string
	Kind string
	// LongestGap is the most time the plan allows between two snapshots;
	// zero for a Receiver.
	LongestGap time.Duration
	// Jitter is the window the plan's slots move by.
	Jitter time.Duration
	// CommitEvery is how often a Receiver commits while its database
	// writes.
	CommitEvery time.Duration
}

Expectation is how often one set gets a snapshot by its agent's plan.

func (Expectation) Validate

func (e Expectation) Validate() error

Validate reports an Expectation without a set, of an unknown kind, with a negative duration, or without the gap or commit interval its kind takes, as ErrInvalid.

type Report

type Report struct {
	Agent string
	Sets  []Expectation
}

Report is what an agent plans: an Expectation per set it writes. It replaces what the agent reported before, so a set it no longer lists expects nothing.

type Reported

type Reported struct {
	Expectation
	Agent string
	Since time.Time
	At    time.Time
}

Reported is the Expectation a store keeps for a set: the last one an agent reported, the agent, since when that agent reports the set and when it last did.

func (Reported) Late

func (r Reported) Late(newest, now time.Time) bool

Late reports whether the set is late at now, given when the store received its newest snapshot, zero for none: once its agent is Silent, whatever that snapshot, and otherwise, but for a Receiver, once its LongestGap, Jitter and Grace passed since that snapshot, or since r's agent first reported the set if that is later. A Stale r is never late.

func (Reported) Silent

func (r Reported) Silent(now time.Time) bool

Silent reports whether r's agent is more than SilentAfter past its due report at now.

func (Reported) Stale

func (r Reported) Stale(now time.Time) bool

Stale reports whether r expired at now.

type Reporter

type Reporter interface {
	ReportSchedule(ctx context.Context, r Report) error
}

Reporter takes an agent's Report; one that cannot is backup.ErrNotImplemented.

Jump to

Keyboard shortcuts

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