Scheduler API
PyScheduler Object
Section titled “PyScheduler Object”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 |
scheduler.cron()
Section titled “scheduler.cron()”# Run every hour at minute 0scheduler.cron("0 * * * *", my_task)| Parameter | Type | Description |
|---|---|---|
expression |
str |
Standard 5-field cron expression (min hour day month weekday) |
callback |
callable | Function to execute |
scheduler.interval()
Section titled “scheduler.interval()”# Run every 30 secondsscheduler.interval(30, my_task)| Parameter | Type | Description |
|---|---|---|
seconds |
int |
Interval in seconds |
callback |
callable | Function to execute |
scheduler.once()
Section titled “scheduler.once()”# Run once after 60 secondsscheduler.once(60, my_task)| Parameter | Type | Description |
|---|---|---|
delay_seconds |
int |
Delay before execution |
callback |
callable | Function to execute |
Integration with App
Section titled “Integration with App”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 hoursSee Also
Section titled “See Also”- Background Tasks — Per-request background tasks
- JustAPIApp — App configuration