Skip to content

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 ​

FieldRangeSupports
minute0–59*, number, */step, 1-5, 1,2,3
hour0–23same as above
day1–31same, plus L for last day of month
month1–12same, plus month names (jan, feb, …)
weekday0–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