Skip to main content

Module cron

Module cron 

Source
Expand description

eclipse cron: prompts that run on a timer.

Three files, all under one root: <root>/cron/jobs.toml says what should run and when, <root>/state/cron.json remembers what did, and <root>/cron/runs/<job>/<ms>.md is what came back. The jobs file is yours to edit — the tool and the CLI write the same format — and a hand-edit is never lost: nothing here rewrites blocks it was not asked to touch.

Time is the hard part. A schedule of “daily 07:30” means 07:30 where the person is, not 07:30 UTC, and the project takes no date-time dependency, so local time comes from libc (offset at an instant, and the civil calendar) with a pure-Rust civil-date conversion that is also what the tests use. An interval schedule never consults a calendar at all.

Nothing here runs an agent: due decides, and the caller runs. That keeps the decision testable with a clock the test controls, and keeps the core free of a dependency cycle (runtime depends on this, not the other way round).

Structs§

Draft
A job as a surface submits it: cron add’s arguments, or a page’s form.
Job
A named job: what to say, when to say it.
JobState
JobView
One job, plus what has run and when it fires next.
Lock
Held for the duration of one tick, so two timers (a systemd one and a hand-run one) cannot run the same job twice.
RunView
One run of a job, as a surface reads it.
State

Enums§

Schedule
When a job fires.

Constants§

ANSWER_CAP
How much of a run’s first line fits in a table: enough to know what happened, short enough to sit in one row. The rest is in RunView::text.
MIN_EVERY_SECS
A minute is the floor: anything finer is a busy loop wearing a schedule’s clothes, and the timer that drives these ticks wakes once a minute anyway.
RUN_TEXT_CAP
How much of a run’s text a surface is handed. A job that answers in ten thousand words is a job whose log is an essay; the page shows the beginning and says the rest is on disk in path, rather than shipping a megabyte of JSON to a browser to render four lines of it.
STALE_LOCK_MS
How long a lock may be ignored before it is taken as abandoned.

Functions§

append_job
Append a job to the file, creating it with a one-line explanation if it does not exist.
due
The jobs that should run now.
expand_tilde
~/x and $HOME/x as the path they mean.
iso_local
2026-11-29 07:30, in local time.
jobs_path
Where jobs live: <root>/cron/jobs.toml.
load
Read <root>/cron/jobs.toml. A missing file is not an error: it is a machine with no jobs.
load_reporting
Read <root>/cron/jobs.toml and say which blocks are unusable.
load_state
local_parts
(year, month, day, hour, minute) in local time.
lock
next_due_for
When a job fires next, given what has run. None for a disabled job.
recent_runs
The most recent runs of a job, newest first.
remove_job
Remove a job by name, leaving every other block exactly as it was.
replace_job
Replace a job’s [[job]] block in place, leaving every other byte of the file alone.
runs
The newest runs of one job, read off the files the tick wrote.
runs_dir
runs_root
Where a job’s run history goes: <root>/cron/runs/<name>/. Every job’s run logs: <root>/cron/runs, before a job name is appended.
save_state
seed_first_seen
Give every job a state entry the first time a tick sees it (#561).
set_enabled
Turn a job on or off, in place. false when no job has that name.
state_path
Where <root>/state/cron.json — the record of what ran — lives.
validate_job_name
Names become directory names, so they are held to the same alphabet as profile names.
view
views
Every job, in the order the file has them, as a surface reads them.
weekday_of
Which day of the week a local instant falls on: 0 = Sunday.
write_run
The run log for one execution: <root>/cron/runs/<job>/<ms>.md.