Queue

Queues let you run background work reliably: enqueue a job with a payload, then have a worker pull it, process it, and ack or nack the result.

Queues are REST-only. Use QPub.Rest (or raw HTTP). The Socket client does not enqueue or pull jobs.

Concepts

ConceptDescription
QueueNamed stream of jobs for a project
JobOne work item (payload, status, attempts)
WorkerYour process that pulls and completes jobs

Typical job statuses you will see: pending, scheduled, running, completed, failed, cancelled, dlq.

Quick example

import { QPub } from "@qpub/sdk";

const rest = new QPub.Rest({ apiKey: process.env.QPUB_API_KEY });

await rest.queues.updateConfig("emails", {
  maxAttempts: 5,
});

await rest.queues.enqueue("emails", {
  to: "[email protected]",
  subject: "Welcome",
});

// Blocks until stopWorker() is called
await rest.queues.runWorker("emails", async (job) => {
  // send email from job.payload
  return { sent: true };
});

Permissions

Producers need enqueue (or publish) on the queue name. Workers need dequeue (or subscribe). See Permissions.

Next