cronspec

package
v0.0.199 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cronspec parses schedule specs for `agent-pro usage collect --cron`.

Accepted forms:

5-field cron   "*/5 * * * *", "0 9 * * 1-5"
macros         @hourly @daily @midnight @weekly @monthly
interval       "@every 10m", or a bare duration "10m" / "300" (seconds)

Cron fields are minute, hour, day-of-month, month, day-of-week. Each accepts "*", "a", "a-b", "*/n", "a-b/n" and comma-separated lists of those. Day-of-week is 0-7 with both 0 and 7 meaning Sunday. When day-of-month and day-of-week are both restricted, a time matches when either one matches (Vixie cron semantics).

Index

Constants

This section is empty.

Variables

View Source
var ErrNeverFires = errors.New("schedule never fires")

ErrNeverFires reports a valid spec that cannot produce another fire time.

Functions

func Run

func Run(ctx context.Context, s Schedule, opts RunOptions, fn func(context.Context) error) error

Run calls fn immediately, then once per scheduled fire, until ctx is cancelled or MaxRuns cycles have completed. The first cycle runs without an initial wait, matching kool for-every. Errors returned by fn are reported through Logf and do not stop the loop; Run returns nil on clean cancellation.

Types

type RunOptions

type RunOptions struct {
	// MaxRuns stops the loop after this many cycles. 0 means unlimited.
	MaxRuns int
	// Now is the clock; nil means time.Now.
	Now func() time.Time
	// Logf receives schedule progress lines; nil means silent.
	Logf func(format string, args ...any)
}

RunOptions configures Run.

type Schedule

type Schedule interface {
	// Next returns the first fire time strictly after after, in after's
	// location. The zero time means the spec can never fire again.
	Next(after time.Time) time.Time
	// String returns the canonical spec text.
	String() string
}

Schedule is a parsed spec that can compute its next fire time.

func Parse

func Parse(spec string) (Schedule, error)

Parse parses spec into a Schedule.

Jump to

Keyboard shortcuts

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