1. SDK Reference
  2. scheduleEvent Trigger

Usage

import { scheduleEvent } from "@trigger.dev/sdk";

new Trigger({
  id: "usage",
  name: "usage",
  on: scheduleEvent({ rateof: { minutes: 10 } }),
  run: async (event, ctx) => {},
}).listen();

Options

You must use one of the following options, but not both:

rateOf
object

The rate of the schedule. This can be a number of minutes, hours, or days. For example, { rateOf: { minutes: 10 } } will run every 10 minutes.

cron
string

A cron expression to run the workflow on. For example, 0 0 * * * will run the workflow every hour at the top of the hour. See crontab.guru for more information.

Event Payload

scheduledTimeRequired
Date

The time the event was scheduled to run.

lastRunAt
Date

The time the event last run. This will be undefined if the event has never run. Use this parameter to run window queries:

import { scheduleEvent, Trigger } from "@trigger.dev/sdk";

new Trigger({
  id: "usage",
  name: "usage",
  on: scheduleEvent({ rateof: { minutes: 10 } }),
  run: async (event, ctx) => {
    const { lastRunAt, scheduledTime } = event;

    const query = `SELECT * FROM users WHERE created_at < ${scheduledTime}`;

    if (lastRunAt) {
      query += ` AND created_at > ${lastRunAt}`;
    }

    const latestUsers = await db.query(query);

    // ...
  },
}).listen();