schedule

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 14 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 schedule is what the daemon knows about schedules (定期実行) besides running them: whether one is valid, when it runs, and the record of its runs.

Index

Constants

View Source
const (
	DefaultTimeoutMin    = 60
	DefaultRetryDelayMin = 5
)

The time limit, retries and stopping after failures (#1083).

View Source
const (
	SummaryLines = 50
	// SummaryRead is how much of the end of a run's output the summary is
	// made from.
	SummaryRead = 64 << 10
)

A run's summary (ScheduleTry.Summary) keeps the end of its output: SummaryLines lines at most, wire.ScheduleSummaryMax bytes at most.

View Source
const MaxRuns = 200

MaxRuns is how many runs (times, their retries in their lines) a schedule's record keeps, the newest ones.

Variables

This section is empty.

Functions

func HostClockAt

func HostClockAt(loc, host *time.Location, at time.Time) *wire.HostClock

HostClockAt is the host's own clock, host (time.Local), at at when it is not loc's (their UTC offsets then differ); nil when it is.

func Latest

func Latest(w wire.ScheduleWhen, loc *time.Location, at, now time.Time) time.Time

Latest is the newest time of w from at (a time of w not after now) up to now. The times missed while a host slept or its daemon was not running run once, as this one.

func Location

func Location(tz string) (*time.Location, error)

Location is the time zone tz names: an IANA name, never "" or "Local" (a schedule never runs on the host's own clock).

func Next

func Next(w wire.ScheduleWhen, loc *time.Location, after time.Time) (time.Time, bool)

Next is the first time after after that w names on the wall clock of loc; false when there is none (w is not valid). A wall-clock time a daylight saving change skips runs at the time it turns into (2:30 → 3:30); one it repeats runs once, the first time.

func NextN

func NextN(w wire.ScheduleWhen, loc *time.Location, after time.Time, n int) []time.Time

NextN is the next n times after after.

func Normalize

func Normalize(s wire.Schedule) wire.Schedule

Normalize drops what s's kind does not use, gives an agent schedule its permission (read when none), gives the time limit and retry delay their defaults and drops the failure count (the daemon's).

func OffsetAt

func OffsetAt(loc *time.Location, at time.Time) int

OffsetAt is the UTC offset in seconds (east positive) of loc at at.

func OutputSummary

func OutputSummary(raw []byte, whole bool) string

OutputSummary turns the end of a terminal's raw output into the plain text it showed, its last SummaryLines lines within ScheduleSummaryMax bytes. Escape sequences are dropped, a line redrawn after \r or \b keeps what was written last, and an erase-in-line (CSI K) clears. whole says raw starts at the beginning of the output; otherwise its first line, which may begin inside a sequence or a character, is dropped.

func RetryDelay

func RetryDelay(s wire.Schedule) time.Duration

RetryDelay is how long after a run that failed s waits to run again.

func Timeout

func Timeout(s wire.Schedule) time.Duration

Timeout is s's time limit (0: none).

func Validate

func Validate(s wire.Schedule) error

Validate checks s as schedule.create takes it; the directory itself is not looked at.

func ValidateRun

func ValidateRun(s wire.Schedule) error

ValidateRun checks what schedule.preview needs: the kind, its command, the time zone and the times.

func ValidateWhen

func ValidateWhen(w wire.ScheduleWhen) error

ValidateWhen checks the times.

Types

type RunLog

type RunLog struct {
	Dir string
}

RunLog is the record of every schedule's runs: Dir/<schedule id>.jsonl, one line per run (a time of the schedule, or run_now; its retries go on in its line, AddTry), oldest first. A run's line is written when it starts and rewritten when a try of it starts or ends; each write replaces the file (it holds MaxRuns lines at most). Its writer, the daemon, serializes the calls.

func (RunLog) Add

func (rl RunLog) Add(id string, r wire.ScheduleRun) error

Add records a new run of schedule id, dropping the oldest beyond MaxRuns.

func (RunLog) AddTry

func (rl RunLog) AddTry(id string, r wire.ScheduleRun, try wire.ScheduleTry) (wire.ScheduleRun, error)

AddTry starts try as the newest of run r's line (a retry): r's newest try moves to its tries. It returns r as it is now; a run no longer kept is not added again.

func (RunLog) Last

func (rl RunLog) Last(id string) (wire.ScheduleRun, bool, error)

Last returns the newest run of schedule id (false: none).

func (RunLog) List

func (rl RunLog) List(id string) ([]wire.ScheduleRun, error)

List returns the runs of schedule id, newest first.

func (RunLog) Remove

func (rl RunLog) Remove(id string) error

Remove deletes the record of schedule id (none is fine).

func (RunLog) Running

func (rl RunLog) Running(id string) ([]wire.ScheduleRun, error)

Running returns the runs of schedule id still marked running.

func (RunLog) Update

func (rl RunLog) Update(id string, r wire.ScheduleRun) error

Update replaces the line of r.RunID; a run no longer kept is not added again.

Jump to

Keyboard shortcuts

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