Skip to content

Scheduler API

The scheduler manages periodic tasks using cron expressions. It runs entirely in Rust with UTC-based timing.

from justapi import PyScheduler
scheduler = PyScheduler()
Method Description
scheduler.cron(expression, callback) Schedule task with cron expression
scheduler.interval(seconds, callback) Schedule task at fixed interval
scheduler.once(delay_seconds, callback) Schedule one-time delayed task
# Run every hour at minute 0
scheduler.cron("0 * * * *", my_task)
Parameter Type Description
expression str Standard 5-field cron expression (min hour day month weekday)
callback callable Function to execute
# Run every 30 seconds
scheduler.interval(30, my_task)
Parameter Type Description
seconds int Interval in seconds
callback callable Function to execute
# Run once after 60 seconds
scheduler.once(60, my_task)
Parameter Type Description
delay_seconds int Delay before execution
callback callable Function to execute
from justapi import JustAPIApp, PyScheduler
app = JustAPIApp()
scheduler = PyScheduler()
def cleanup_expired_sessions():
app.db.execute("DELETE FROM sessions WHERE expires_at < NOW()")
scheduler.cron("0 */6 * * *", cleanup_expired_sessions) # Every 6 hours