Cron
Server-side scheduling — run a callback on an interval, at a time of day, or on a cron expression.
Server-side scheduling — run a callback on an interval, at a time of day, or on a cron expression.
lib.cron schedules server-side jobs. Each call returns a CronJob you can stop(). Server-side only.
local job = lib.cron.every('5m', function()
cleanupExpired()
end)
job.stop() -- when you're doneevery(interval, callback, onError?) — interval is a number + unit: s, m or h (e.g. '30s', '5m', '2h').
lib.cron.at('03:00', function()
nightlyReset()
end)at(timeStr, callback, onError?) — timeStr is HH:MM (24h). Fires every day at that time.
-- every weekday at 08:30
lib.cron.new('30 8 * * 1-5', function()
openShops()
end)new(expression, callback, onError?) — a standard 5-field cron expression minute hour day month weekday:
| Field | Range | Extras |
|---|---|---|
| minute | 0–59 | |
| hour | 0–23 | |
| day | 1–31 | L = last day of the month |
| month | 1–12 | names jan–dec |
| weekday | 0–7 | names sun–sat (0 and 7 = Sunday) |
L = last day of the monthjan–decsun–sat (0 and 7 = Sunday)Each field supports *, lists (1,3,5), ranges (1-5) and steps (*/15). Resolution is one minute.
Every scheduler returns a CronJob:
job.stop() — cancel the job.job.isActive() → boolean — whether it's still running.A third argument onError(message) is called if your callback throws — the job keeps running.
Server-side only. An invalid interval / time / expression logs an error and returns a no-op job (it never fires) rather than crashing. new checks once a minute, so it can't do sub-minute precision — use every for that.