Docs / Guides / Task scheduler

Platform 05 · Study guide

Task scheduler

Register recurring tasks in app/schedule.py and run due work from cron or a supervisor.

What you will learn
  • Where to register schedule entries
  • How to list and run due tasks
  • How to wire OS cron to tpy schedule run

1. Setup

tpy new scaffolds app/schedule.py. Edit register():

# app/schedule.py
def register(schedule):
    schedule.command("cache:clear").daily()
    schedule.call(lambda: print("heartbeat")).every_minute()
$ tpy schedule list
$ tpy schedule run

2. How it works

  1. CLI loads app.schedule.register.
  2. Each event has a cadence (every minute, hourly, daily, cron expression helpers).
  3. tpy schedule run executes only tasks that are due now.
  4. Overlap locks prevent stacking the same task if a previous run is still active.

3. Production wiring

# cron example — every minute
* * * * * cd /var/www/myapp && tpy schedule run

Combine with queue workers: schedule can enqueue Jobs instead of doing heavy work inline.