Examples
Schedules
Create a schedule that runs every 5 minutes
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
await 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>" });
const schedules = client.schedules();
await schedules.create({
destination: "https://my-api...",
cron: "0 * * * *",
callback: "https://my-callback...",
failureCallback: "https://my-failure-callback...",
});
Create a schedule to a topic that runs every minute
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
await schedules.create({
destination: "my-topic",
cron: "* * * * *",
});
Get a schedule by schedule id
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
const res = await schedules.get("scheduleId");
console.log(res.cron);
List all schedules
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
const allSchedules = await schedules.list();
console.log(allSchedules);
Delete a schedule
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
await schedules.delete("scheduleId");