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
});
Pause/Resume a schedule
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const scheduleId = "my-schedule"
// pause schedule
await client.schedules.pause({ schedule: scheduleId });
// check if paused
const result = await client.schedules.get(scheduleId);
console.log(getResult.isPaused) // prints true
// resume schedule
await client.schedules.resume({ schedule: scheduleId });
Was this page helpful?