st.cron — Scheduled Tasks (Server)
lua
---@param expression string Cron expression: "minute hour day month weekday"
---@param job function Called with (task, date) when the schedule fires
---@param options? table { debug?: boolean, maxDelay?: number }
local task = st.cron.new(expression, job, options)Cron expression syntax
| Field | Range | Supports |
|---|---|---|
| minute | 0–59 | *, number, */step, 1-5, 1,2,3 |
| hour | 0–23 | same as above |
| day | 1–31 | same, plus L for last day of month |
| month | 1–12 | same, plus month names (jan, feb, …) |
| weekday | 0–7 (0/7=Sun) | short names (sun, mon, …), ranges |
Examples
lua
-- Every day at midnight
st.cron.new('0 0 * * *', function(task, date)
print('Midnight reset')
end)
-- Every 15 minutes
st.cron.new('*/15 * * * *', function(task, date)
print('15-minute tick')
end)
-- Every Monday at 08:00
st.cron.new('0 8 * * mon', function(task, date)
print('Monday morning')
end, { debug = true })Task control
lua
task:stop() -- Stop the task
task:run() -- Restart a stopped task
task.isActive -- boolean