Cron
A built-in background scheduler. Each job runs on its own thread, non-blocking.
-- Doc example: cron scheduler. Jobs run in the background; see the prose for cron_every.
-- Doctest just shows the registry starts empty (no jobs scheduled yet).
intent: "doc example: cron"
print("scheduled jobs: " + text(length(cron_list())))
test "the job registry starts empty"
assert_eq(length(cron_list()), 0)
Scheduling
task sync_inventory()
let data be http_get("https://api.warehouse.com/stock")
share data as "inventory"
cron_every(300, sync_inventory) -- every 5 minutes
cron_after(3600, send_reminder) -- once, after 1 hour
Managing
cron_cancel("sync_inventory") -- stop a job
let jobs be cron_list() -- list all jobs
print(cron_status()) -- formatted status
Keeping jobs alive
Under run, jobs stop when the program ends (they're daemon threads). Use synsema serve to keep the process — and the schedule — running:
synsema serve scheduler.syn -- "Serving N cron job(s). Press Ctrl+C to stop."