Skip to main content
Scheduled tasks are for recurring work. To trigger a one-off task at a future time, use the delay option when triggering.

Defining a scheduled task

Use schedules.task() to define a task that runs on a schedule. The payload argument contains useful properties about the current invocation:
/trigger/first-scheduled-task.ts
The payload fields are:
This task will not run on a schedule until you attach at least one schedule to it.

How to attach a schedule

There are two ways to attach a schedule to a schedules.task():
  • Declarative — defined directly on the task. Synced automatically when you run dev or deploy.
  • Imperative — created from the dashboard or via SDK functions like schedules.create().
A single scheduled task can have multiple schedules attached — a declarative one and/or many imperative ones.

Declarative schedules

Add a cron property to your schedules.task(). This is synced when you run the dev or deploy commands. A string value runs in UTC:
/trigger/every-two-hours.ts
To specify a timezone, use the object form:
/trigger/daily-tokyo.ts

Imperative schedules

Create schedules dynamically at runtime using schedules.create(). Imperative schedules can be created, updated, activated, deactivated, and deleted without redeploying code. This is useful when each of your users needs their own schedule:
/trigger/reminder.ts
Create a schedule for each user from your backend:
Next.js API route

Supported cron syntax

L means “last”. In the day-of-week field, 1L means the last Monday of the month. In the day-of-month field, L means the last day of the month.
Seconds are not supported in the cron syntax.

When schedules will not trigger

  • Development environment — scheduled tasks only trigger while the dev CLI is running.
  • Production/Staging — scheduled tasks only trigger for the current deployment. Tasks from previous deployments are not triggered.

Attaching schedules in the dashboard

1

Go to the Schedules page

In the sidebar, select the Schedules page, then press New schedule.
2

Create your schedule

Fill in the form and press Create schedule.

Attaching schedules with the SDK

schedules.create()

Managing schedules with the SDK

Testing scheduled tasks

You can trigger a scheduled task from the Test page in the dashboard. The scheduleId will always be sched_1234 in a test run.
1

Go to the Test page

In the sidebar, select Test, then choose a scheduled task from the list (they have a clock icon).
2

Fill in the form and run

Set the timestamp and any other fields, then press Run test. You can also select from a recent run to pre-populate the form.