Schedule a Python function to run periodically using Resonate's high-level schedule() API.
Running a function on a cron schedule sounds simple — but in practice, what happens when the worker crashes mid-execution? Traditional cron jobs offer no crash recovery: the job just doesn't run (or runs again from scratch on the next tick). Resonate makes scheduled executions durable. Each cron tick fires a new durable promise. If the worker crashes while processing it, Resonate retries automatically. No lost ticks, no manual recovery logic.
This example shows how to use Resonate's schedule() method to register a function as a periodic job using a cron expression. The Resonate server triggers the function automatically, and a worker processes each execution durably.
# Register the function
resonate.register(generate_report)
# Schedule it to run every minute
resonate.schedule(
"daily_report", # schedule ID
generate_report, # function to schedule
"* * * * *", # cron expression
user_id=123, # arguments
)- Python 3.12+
- uv (recommended) or pip
- Resonate server running locally
resonate devuv syncRun this once to register the cron schedule with the Resonate server:
uv run python schedule.pyRun the worker to process each scheduled execution:
uv run python worker.pyEvery minute, you'll see output like:
[2026-02-18T09:00:00] Report for user 123
[2026-02-18T09:01:00] Report for user 123
| File | Role |
|---|---|
schedule.py |
Creates the cron schedule on the Resonate server (run once) |
worker.py |
Registers the function and polls for executions (run continuously) |
report.py |
The function that runs on each scheduled tick |
The Resonate server fires a new durable promise on each cron tick. The worker picks it up, executes the function, and records the result. If the worker crashes, Resonate retries the execution automatically.
| Expression | Meaning |
|---|---|
* * * * * |
Every minute |
0 9 * * * |
Daily at 9am |
0 9 * * 1-5 |
Weekdays at 9am |
*/30 * * * * |
Every 30 minutes |