Skip to content
Get started
Get started
Queue API: Add and Manage Jobs in Bun
View Markdown
guide · queue

The producer side.

A Queue is where work goes in. It is the same object whether it writes to SQLite in your process or talks over TCP to a memory-, SQLite-, or PostgreSQL-backed server, so client code does not change when the deployment does.

Start here: create the queue, pick a mode, and know which options belong to the constructor rather than to individual jobs.

import { Queue } from 'bunqueue/client';
const queue = new Queue('my-queue', { embedded: true });
await queue.add('job-name', { key: 'value' });

Useful variations:

// Typed queue: job.data is type-checked
interface TaskData {
userId: number;
action: string;
}
const typedQueue = new Queue<TaskData>('tasks', { embedded: true });
// Default options applied to every job
const emailQueue = new Queue('emails', {
embedded: true,
defaultJobOptions: {
attempts: 3,
backoff: 1000,
removeOnComplete: true,
},
});
// TCP mode with a custom connection
const remoteQueue = new Queue('tasks', {
connection: {
host: '192.168.1.100',
port: 6789,
token: 'secret-token', // If AUTH_TOKENS is set on the server
poolSize: 4, // Connection pool size
},
});

The two TypeScript packages share the same Queue API, including defaultJobOptions, prefixKey, auto-batching, and nested connection.poolSize. Use embedded: false on Node.js and Deno; embedded storage requires Bun. In the other SDKs, pass connection options to the constructor (see SDKs) and job options per add call.

GuideWhat it covers
Adding Jobsadd, addBulk, priorities, delays, durability
Deduplication and Idempotent Job AddsIdempotent adds, dedup keys, custom job ids
Querying JobsFetch jobs, states, counts and results
Queue Control and MaintenancePause, drain, obliterate, clean and repair
Progress, Job Logs and DependenciesProgress, per-job logs and dependencies
Queue Rate Limiting and Global ConcurrencyRate limits and global concurrency caps
Job GroupsPer-group priority/FIFO, fairness and capacity
Job Schedulers from the QueueNamed repeatable schedules from the queue
DLQ Operations from the Queue ObjectFailed-job operations from the Queue object
Workers, Stats and Metrics from the QueueRegistered workers, stats and metrics windows
Namespaces, Auto-Batching and Store-and-ForwardNamespaces, auto-batching, store-and-forward
JobOptions ReferenceEvery JobOptions field, with defaults