Cron & Timers

Run code on a schedule

Run code on a schedule without a separate scheduler. Declare cron expressions in ploy.yaml, including six-field expressions for sub-minute schedules, and implement a scheduled handler. For delays and reminders set from code, durable timers fire your worker at a specific time and survive restarts.

Scheduled Runs

Cron Runs

Every trigger in ploy.yaml, with its last run

TriggerExpressionStatusDurationLast run
EVERY_10_SECONDS*/10 * * * * *
Success
42ms8 seconds ago
HOURLY_CLEANUP0 * * * *
Success
1.9s14 minutes ago
DAILY_REPORT0 9 * * *
Running
—just now
WEEKLY_DIGEST0 10 * * 1
Success
5.2s2 days ago

Scheduled Handler

One handler receives every trigger; branch on event.cron

src/index.ts
export default {
  async scheduled(event, env) {
    if (event.cron === "0 9 * * *") {
      await env.TASKS.send({ job: "daily-report" });
    }
  },
} satisfies Ploy;

Key Features

Cron Expressions

Standard five-field expressions, plus a leading seconds field for schedules like every ten seconds.

Durable Timers

Schedule a one-shot or recurring timer from code. Timers survive restarts and fire at least once.

Multiple Triggers

Name each schedule and branch on event.cron to run different jobs from one worker.

Runs Locally Too

ploy dev fires your schedules on time and shows the run history in the local dashboard.

Cron Triggers

Each key in cron is a trigger name; the scheduled handler receives the expression that fired.

ploy.yaml
kind: worker
build: pnpm build
out: dist
cron:
  EVERY_10_SECONDS: "*/10 * * * * *"
  HOURLY_CLEANUP: "0 * * * *"
  DAILY_REPORT: "0 9 * * *"

Ready to get started?

Deploy your first project in minutes with Ploy.