Examples

Schedules

Create a schedule that runs every 5 minutes

import { Client } from "@upstash/qstash";const client = new Client({ token: "<QSTASH_TOKEN>" });await client.schedules.create({  destination: "https://my-api...",  cron: "*/5 * * * *",});

Create a schedule that runs every hour and sends the result to a callback URL

import { Client } from "@upstash/qstash";const client = new Client({ token: "<QSTASH_TOKEN>" });await client.schedules.create({  destination: "https://my-api...",  cron: "0 * * * *",  callback: "https://my-callback...",  failureCallback: "https://my-failure-callback...",});

Create a schedule to a URL Group that runs every minute

import { Client } from "@upstash/qstash";const client = new Client({ token: "<QSTASH_TOKEN>" });await client.schedules.create({  destination: "my-url-group",  cron: "* * * * *",});

Get a schedule by schedule id

import { Client } from "@upstash/qstash";const client = new Client({ token: "<QSTASH_TOKEN>" });const res = await client.schedules.get("scheduleId");console.log(res.cron);

List all schedules

import { Client } from "@upstash/qstash";const client = new Client({ token: "<QSTASH_TOKEN>" });const allSchedules = await client.schedules.list();console.log(allSchedules);

Create/overwrite a schedule with a user chosen schedule id

Note that if a schedule exists with the same id, the old one will be discarded and new schedule will be used.

Typescript
import { Client } from "@upstash/qstash";const client = new Client({ token: "<QSTASH_TOKEN>" });await client.schedules.create({  destination: "https://example.com",  scheduleId: "USER_PROVIDED_SCHEDULE_ID",  cron: "* * * * *",});

Delete a schedule

import { Client } from "@upstash/qstash";const client = new Client({ token: "<QSTASH_TOKEN>" });await client.schedules.delete("scheduleId");

Create a schedule with timeout

Timeout value in seconds to use when calling a schedule URL (See Upstash-Timeout in Create Schedule page).

import { Client } from "@upstash/qstash";const client = new Client({ token: "<QSTASH_TOKEN>" });await client.schedules.create({  url: "https://my-api...",  cron: "* * * * *",  timeout: "30" // 30 seconds timeout});

Create a schedule with labels

Labels tag the schedule so you can later identify and filter the messages it produces in the logs.

import { Client } from "@upstash/qstash";const client = new Client({ token: "<QSTASH_TOKEN>" });// attach a single labelawait client.schedules.create({  destination: "https://my-api...",  cron: "* * * * *",  label: "my-label",});// attach multiple labels to the same scheduleawait client.schedules.create({  destination: "https://my-api...",  cron: "* * * * *",  label: ["team-a", "high-priority"],});

Pause/Resume a schedule

import { Client } from "@upstash/qstash";const client = new Client({ token: "<QSTASH_TOKEN>" });const scheduleId = "my-schedule"// pause scheduleawait client.schedules.pause({ schedule: scheduleId });// check if pausedconst result = await client.schedules.get(scheduleId);console.log(getResult.isPaused) // prints true// resume scheduleawait client.schedules.resume({ schedule: scheduleId });
Loading search…