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

cron

package
v0.1.2 Latest Latest
Warning

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

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

Documentation

Overview

Package cron holds the pure scheduling domain for rysh's in-daemon cron service: the Job model, schedule parsing/validation (via robfig/cron), and next-run computation. It has no actor or NATS dependencies so it is fully unit-testable; the actor-side store, ticker, and job firing live in internal/actors/workspace_cron.go.

Index

Constants

View Source
const AutoDisableAfter = 5

AutoDisableAfter is the consecutive-failure count at which a job is auto-disabled.

View Source
const MaxJobs = 100

MaxJobs caps the number of jobs a session may hold.

View Source
const MaxRunHistory = 20

MaxRunHistory caps the per-job ring buffer of recent run records.

Variables

This section is empty.

Functions

func ParseSchedule

func ParseSchedule(schedule, tz string) (robfig.Schedule, error)

ParseSchedule parses a cron spec (5-field standard, or @every/@daily/… descriptors) with an optional timezone.

func Validate

func Validate(name, schedule, tz, input string) error

Validate checks a job's name, schedule, and input at creation time.

Types

type Job

type Job struct {
	ID       string `json:"id"`
	Name     string `json:"name"`     // unique handle for ##cron commands
	Schedule string `json:"schedule"` // "0 9 * * *", "@every 15m", "@daily"
	Timezone string `json:"timezone,omitempty"`
	Target   string `json:"target"` // pane id/name, or "active"
	Mode     string `json:"mode"`   // shell | prompt | rysh (inferred if empty)
	Input    string `json:"input"`  // text to inject (##…, @agent…, prompt, shell)
	Enabled  bool   `json:"enabled"`

	NextRun    time.Time `json:"next_run"`
	LastRun    time.Time `json:"last_run,omitempty"`
	LastStatus string    `json:"last_status,omitempty"`
	RunCount   int       `json:"run_count"`
	Runs       []Run     `json:"runs,omitempty"`

	// FailStreak counts consecutive failures; the actor auto-disables a job
	// after AutoDisableAfter consecutive failures so a broken job can't fire
	// forever.
	FailStreak int `json:"fail_streak,omitempty"`
}

Job is a scheduled rysh input injection.

func (*Job) ComputeNext

func (j *Job) ComputeNext(from time.Time) error

ComputeNext sets NextRun to the first fire time strictly after `from`. Returns an error if the schedule no longer parses (e.g. corrupted KV).

func (*Job) Due

func (j *Job) Due(now time.Time) bool

Due reports whether the job should fire at time `now`: enabled and its NextRun has arrived.

func (*Job) InferMode

func (j *Job) InferMode() string

InferMode returns the effective input mode: the explicit Mode, else inferred from the input prefix (## / @ → those are handled by the dispatcher regardless of mode, so default to "prompt" for bare text is wrong for shell; we default bare text to "shell" to match a terminal's expectation).

func (*Job) RecordRun

func (j *Job) RecordRun(r Run)

RecordRun appends a run record (ring-buffered), updates last-run bookkeeping, and maintains the failure streak.

type Run

type Run struct {
	At     time.Time `json:"at"`
	Status string    `json:"status"` // ok | error | skipped
	Note   string    `json:"note,omitempty"`
}

Run is one recorded firing of a job.

Jump to

Keyboard shortcuts

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