Skip to content

resonatehq-examples/example-schedule-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scheduled Function | Resonate Example

Schedule a Python function to run periodically using Resonate's high-level schedule() API.

What problem does this solve?

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.

Overview

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
)

Prerequisites

Setup

1. Start the Resonate server

resonate dev

2. Install dependencies

uv sync

3. Create the schedule

Run this once to register the cron schedule with the Resonate server:

uv run python schedule.py

4. Start the worker

Run the worker to process each scheduled execution:

uv run python worker.py

Every minute, you'll see output like:

[2026-02-18T09:00:00] Report for user 123
[2026-02-18T09:01:00] Report for user 123

How It Works

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.

Cron Reference

Expression Meaning
* * * * * Every minute
0 9 * * * Daily at 9am
0 9 * * 1-5 Weekdays at 9am
*/30 * * * * Every 30 minutes

Learn More

About

Periodic function scheduling with Resonate's Python SDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages