Skip to main content

Create a queue with parallelism 2

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

const queueName = "upstash-queue";
await client.queue({ queueName }).upsert({ parallelism: 2 });

const queueDetails = await client.queue({ queueName }).get();

Enqueue a message with labels

enqueue and enqueueJSON accept the same options as publish, including label. Labels let you tag the message so you can later filter it in the logs.
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });

const queue = client.queue({ queueName: "upstash-queue" });
await queue.enqueueJSON({
  url: "https://my-api...",
  body: { hello: "world" },
  label: ["team-a", "high-priority"], // single string or array
});

Delete Queue

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

const queueName = "upstash-queue";
await client.queue({ queueName: queueName }).delete();
Resuming or creating a queue may take up to a minute. Therefore, it is not recommended to pause or delete a queue during critical operations.

Pause/Resume a queue

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

const name = "upstash-pause-resume-queue";
const queue = client.queue({ queueName: name });
await queue.upsert({ parallelism: 1 });

// pause queue
await queue.pause();

const queueInfo = await queue.get();
console.log(queueInfo.paused); // prints true

// resume queue
await queue.resume();
Resuming or creating a queue may take up to a minute. Therefore, it is not recommended to pause or delete a queue during critical operations.