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

The producer side.

A Queue is where work goes in. Same object whether it writes straight to a SQLite file in your process or talks to a shared server over TCP, so the code you write 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
}
});

embedded: true and defaultJobOptions exist in the Bun bunqueue package only; the poolSize connection pool is TypeScript-only. In the other SDKs, pass connection options to the constructor (see SDKs) and job options per add call.

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 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