cron

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.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 cron implements the built-in scheduler: a five-field cron parser and a runner that executes natural-language jobs through the agent.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyRunning = errors.New("cron: job already running")

ErrAlreadyRunning is returned when the same job is already executing.

View Source
var ErrCapacityBusy = errors.New("cron: scheduler at capacity")

ErrCapacityBusy is returned when the concurrency limit is full.

View Source
var ErrDisabled = errors.New("cron: scheduler disabled")

ErrDisabled is returned to scheduled callers when the runner is disabled. RunNow does not observe this error; manual runs are allowed regardless.

Functions

func Validate

func Validate(expr string, loc *time.Location) (time.Time, error)

Validate checks an expression and returns the next activation for previews.

Types

type Deliverer

type Deliverer func(ctx context.Context, target, text string) error

Deliverer optionally forwards a job's output to a messaging target.

type Executor

type Executor func(ctx context.Context, job store.CronJob) (sessionID, reply string, err error)

Executor runs one scheduled job's prompt and returns its final reply.

type Options

type Options struct {
	Store         store.Store
	Execute       Executor
	Deliver       Deliverer
	Timezone      string
	MaxConcurrent int
	HistoryLimit  int
	// Enabled controls scheduled activations. nil defaults to true; Main
	// should call Reconfigure at boot to apply the configured value.
	Enabled *bool
}

Options configures a Runner.

type Runner

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

Runner ticks once a minute and executes jobs whose schedule has come due. Runtime configuration is swappable via Reconfigure without stopping the loop or cancelling jobs that are already executing.

func New

func New(o Options) *Runner

New builds a Runner defaulting to enabled=true unless Options.Enabled is non-nil.

func (*Runner) Location

func (r *Runner) Location() *time.Location

Location reports the scheduler timezone.

func (*Runner) Recompute

func (r *Runner) Recompute(ctx context.Context, job *store.CronJob) error

Recompute refreshes one job's next activation, e.g. after an edit.

func (*Runner) Reconfigure added in v0.4.0

func (r *Runner) Reconfigure(enabled bool, timezone string, maxConcurrent int, historyLimit int) error

Reconfigure applies new runtime configuration atomically. Inputs are validated first; a rejected call leaves the runner untouched. A recompute is signalled only when the timezone or enabled flag actually changes.

func (*Runner) RunNow

func (r *Runner) RunNow(ctx context.Context, id string) error

RunNow executes a job immediately, outside its schedule. It honours the concurrency limit and duplicate guard; unlike scheduled activations, RunNow is allowed while the runner is disabled.

func (*Runner) Start

func (r *Runner) Start(ctx context.Context)

Start runs the scheduler loop until ctx is cancelled. The loop runs even while disabled so Reconfigure can re-enable scheduling without a restart.

type Schedule

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

Schedule is a parsed five-field cron expression.

func Parse

func Parse(expr string) (*Schedule, error)

Parse compiles a cron expression. It accepts the five-field form plus the common @daily style shorthands and "@every <duration>".

func (*Schedule) Next

func (s *Schedule) Next(t time.Time) time.Time

Next returns the first activation strictly after t, or the zero time when the expression can never fire (searched up to five years ahead).

func (*Schedule) String

func (s *Schedule) String() string

String returns the original expression.

Jump to

Keyboard shortcuts

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