schedule

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package schedule wraps the cron parser, provides epoch-aligned Every schedules, and computes which periodic ticks are due after a leader gap (catch-up window) and which are skipped.

s, err := schedule.ParseCron("*/5 * * * *", loc)
due, skipped := schedule.DueTicks(s, lastTick, now, 5*time.Minute, 100)

Index

Constants

This section is empty.

Variables

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

ErrInvalid is wrapped by schedule parsing errors.

Functions

func DueTicks

func DueTicks(s Schedule, last, now time.Time, window time.Duration, limit int) (due []time.Time, skipped int)

DueTicks returns the ticks t with last < t <= now that are inside the catch-up window (t >= now - window), oldest first, and the number of earlier ticks that were skipped. At most limit ticks are returned; the skipped count saturates at 100,000.

Types

type Schedule

type Schedule interface {
	// Next returns the first tick strictly after t.
	Next(t time.Time) time.Time
}

Schedule computes tick times. Ticks must be deterministic: every leader computes the same instants, which is what makes the (name, tick) unique constraint enforce exactly-once enqueueing.

func Every

func Every(d time.Duration) (Schedule, error)

Every returns a schedule ticking every d, aligned to multiples of d since the Unix epoch so that every client computes the same ticks. d must be positive.

func ParseCron

func ParseCron(expr string, loc *time.Location) (Schedule, error)

ParseCron parses a standard 5-field cron expression, a 6-field expression with leading seconds, or a descriptor such as @hourly, evaluated in loc (UTC when nil). @every is rejected because its ticks are relative to the evaluating process; use Every instead.

DST follows robfig/cron: a wall time skipped by a spring-forward transition does not fire that day, and a wall time repeated by a fall-back transition fires once per occurrence.

Jump to

Keyboard shortcuts

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