Documentation
¶
Overview ¶
Package cron implements a small, dependency-free standard 5-field cron parser and next-run evaluator for the `zero cron` scheduler.
Index ¶
- Constants
- Variables
- func DefaultRoot(env map[string]string) string
- func ResolveLoopPrompt(cwd, home string) (string, error)
- type Job
- type RecipeDef
- type RunRecord
- type Schedule
- type Store
- func (s *Store) Add(job Job) (Job, error)
- func (s *Store) AppendRun(id string, rec RunRecord) error
- func (s *Store) Get(id string) (Job, error)
- func (s *Store) List() ([]Job, error)
- func (s *Store) Mutate(id string, mutate func(current Job, readErr error) (Job, error)) (Job, error)
- func (s *Store) Remove(id string) error
- func (s *Store) Runs(id string) ([]RunRecord, error)
- func (s *Store) Update(job Job) error
- type StoreOptions
Constants ¶
const ( StatusActive = "active" StatusPaused = "paused" )
Variables ¶
var ErrJobNotFound = errors.New("cron job not found")
ErrJobNotFound is returned (wrapped) by Get when a job's metadata file is absent — a genuinely removed job. Callers use errors.Is to distinguish this from a transient read failure (IO error, permission), which must NOT be treated as "job removed".
Functions ¶
func DefaultRoot ¶
DefaultRoot mirrors sessions.DefaultRoot: <XDG_DATA_HOME|~/.local/share>/zero/cron.
func ResolveLoopPrompt ¶
ResolveLoopPrompt returns the loop prompt for a scheduled job: the first readable loop.md found in <cwd>/.zero, <cwd>/.agents, <home>/.zero, <home>/.agents, else the built-in fallback. Files over maxLoopPromptBytes return an error; symlinks are skipped (never read) to prevent exfiltration.
Types ¶
type Job ¶
type Job struct {
ID string `json:"id"`
Expr string `json:"expr"`
Prompt string `json:"prompt"`
Cwd string `json:"cwd,omitempty"`
Model string `json:"model,omitempty"`
Status string `json:"status"`
FireCount int `json:"fireCount"`
NextRunAt time.Time `json:"nextRunAt"`
CreatedAt time.Time `json:"createdAt"`
}
Job is a stored scheduled job.
type RunRecord ¶
type RunRecord struct {
JobID string `json:"jobId"`
At time.Time `json:"at"`
ExitCode int `json:"exitCode"`
SessionTitle string `json:"sessionTitle,omitempty"`
Error string `json:"error,omitempty"`
}
RunRecord is one fire's outcome, appended to the job's runs.jsonl.
type Schedule ¶
type Schedule struct {
// contains filtered or unexported fields
}
Schedule is a parsed 5-field cron expression. Field sets are bitsets over the field's value range. domStar/dowStar record whether the day-of-month / day-of-week field was "*", which selects the standard Vixie OR semantics.
func Parse ¶
Parse parses a standard 5-field cron expression: minute hour day-of-month month day-of-week. Supports *, lists (a,b), ranges (a-b), steps (*/s, a-b/s, a/s), 3-letter month/weekday names, and 7 as Sunday.
func (Schedule) Next ¶
Next returns the first scheduled instant strictly after `after`, evaluated in after's location. It returns the zero time.Time if no match occurs within nextSearchYears (an impossible schedule such as Feb 30). It is robust to DST gaps: a per-iteration forward-progress guard prevents stalling on a non-existent local instant (e.g. 02:30 on a spring-forward day).
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func NewStore ¶
func NewStore(opts StoreOptions) *Store
func (*Store) Mutate ¶
func (s *Store) Mutate(id string, mutate func(current Job, readErr error) (Job, error)) (Job, error)
Mutate atomically updates job id under the per-job cross-process lock, closing the read-modify-write race between concurrent schedulers (and against Update/ Remove). It re-reads the CURRENT on-disk job and passes it to mutate along with any read error; mutate returns the job to persist. A removed job aborts with ErrJobNotFound (no recreate). A transient read error (not removal) is surfaced via readErr so the caller can still persist a best-effort state — the fire path advances the schedule regardless, to avoid a re-fire.
type StoreOptions ¶
StoreOptions configures a Store. RootDir defaults to DefaultRoot(os env); Now defaults to time.Now. Both injectable for tests.