# HTTP API: Queues, Limits & Config

HTTP REST endpoints for listing queues, inspecting counts, pausing, draining, cleaning, rate limits, concurrency, stall config, and job groups.

Canonical: https://bunqueue.dev/api/http/queues/

---

*[Interactive doc iso diagram: List queues, read per-state counts, pause/resume, and tune rate or stall limits - 21 queue endpoints: inspect exact counts by state, manage paused queues, update rate/concurrency caps live, and configure stall detection - open the HTML page to view it.]*

All 21 queue inspection, lifecycle, limit, and stall-config endpoints under `/queues/*`. See [HTTP API Overview](https://bunqueue.dev/api/http/) for auth and error envelopes.

## Queue Discovery & Inspection

| Method | Path | Response Shape | Notes |
| --- | --- | --- | --- |
| `GET` | `/queues` | `{ "ok": true, "queues": ["emails", "reports"] }` | All queues that have received at least one job (persists until obliterated). |
| `GET` | `/queues/summary` | `[{ "name": "emails", "paused": false, "counts": { ... } }]` | Bare JSON array (no `ok` wrapper); returns paused flag + counts for all queues in one call. |
| `GET` | `/queues/:queue/workers` | `{ "ok": true, "workers": [{ "id", "name", "queues", "concurrency", "registeredAt", "lastSeen", "activeJobs", "processedJobs", "failedJobs" }] }` | Workers currently registered for `:queue`. |
| `GET` | `/queues/:queue/counts` | `{ "ok": true, "counts": { "waiting", "prioritized", "active", "delayed", "completed", "failed", "waiting-children", "paused" } }` | Exact per-state counts. For push updates without polling, subscribe to `queue:counts` via [Real-time Events](https://bunqueue.dev/api/http/realtime-events/). |
| `GET` | `/queues/:queue/count` | `{ "ok": true, "count": 180 }` | Total queued jobs (`waiting` + `prioritized` + `delayed`). |
| `GET` | `/queues/:queue/priority-counts` | `{ "ok": true, "queue": "emails", "counts": { "0": 100, "10": 12 } }` | Breakdown of queued jobs by priority value. |
| `GET` | `/queues/:queue/paused` | `{ "ok": true, "paused": false }` | Current pause state. |

### List Jobs by State

`GET /queues/:queue/jobs/list[?status=waiting&limit=100&offset=0]`

```bash
curl "http://localhost:6790/queues/emails/jobs/list?status=waiting,delayed&limit=20&offset=0"
```

| Query Param | Type | Default | Description |
| --- | --- | --- | --- |
| `status` | `string` | all | Filter by `waiting`, `prioritized`, `delayed`, `paused`, `active`, `completed`, `failed`, `waiting-children`. Aliases: `state`, `states`. Repeatable or comma-separated. |
| `limit` | `number` | `100` | Max jobs returned (parsed via `parseInt`). |
| `offset` | `number` | `0` | Jobs skipped before returning a page (parsed via `parseInt`). |

Ordered by `createdAt` ascending with job ID tie-breaker; state filtering runs before `offset`/`limit` for stable paging. **Response (`200`):** `{ "ok": true, "jobs": [...] }`.

## Queue Control & Maintenance

| Method | Path | Body | Response & Event |
| --- | --- | --- | --- |
| `POST` | `/queues/:queue/pause` | none | Stops new pulls (active jobs finish). Broadcasts `queue:paused`. |
| `POST` | `/queues/:queue/resume` | none | Resumes pulling jobs. Broadcasts `queue:resumed`. |
| `POST` | `/queues/:queue/drain` | none | Removes all `waiting` and `delayed` jobs; active jobs continue. Returns `{ "ok": true, "count": N }`. Broadcasts `queue:drained`. |
| `POST` | `/queues/:queue/obliterate` | none | Irreversibly deletes the queue, queued jobs, and metadata (active ACK/FAIL become no-ops). Broadcasts `queue:obliterated`. |
| `POST` | `/queues/:queue/clean` | `{ "grace"?: 0, "state"?: "waiting", "limit"?: 1000 }` | Removes jobs older than `grace` ms using the O(log n + k) temporal index. Returns `{ "ok": true, "count": N, "ids": [...] }`. Broadcasts `queue:cleaned`. |
| `POST` | `/queues/:queue/promote-jobs` | `{ "count"?: 50 }` | Promotes up to `count` delayed jobs (omit `count` for all). |
| `POST` | `/queues/:queue/retry-completed` | `{ "id"?: "..." }` | Re-queues one completed job or all completed jobs when `id` is omitted. |

```bash
curl -X POST http://localhost:6790/queues/emails/pause
curl -X POST http://localhost:6790/queues/emails/drain
curl -X POST http://localhost:6790/queues/emails/clean \
  -H "Content-Type: application/json" -d '{"grace": 86400000, "state": "waiting", "limit": 500}'
```

For `/clean`, `state` accepts `waiting`, `delayed`, `prioritized`, `paused` (all clean the queued set; default), `completed`, or `failed`.

> **Caution**
>
> `POST /queues/:queue/obliterate` permanently deletes the queue and removes its name from `GET /queues`.

## Rate Limiting & Concurrency

Per-queue throughput and parallelism controls (independent of per-IP HTTP rate limiting):

### Set / Clear Rate Limit

`PUT /queues/:queue/rate-limit` · `DELETE /queues/:queue/rate-limit`

```bash
curl -X PUT http://localhost:6790/queues/emails/rate-limit \
  -H "Content-Type: application/json" -d '{"limit": 100, "duration": 60000, "ttl": 30000}'
```

- `limit`: Max jobs per window; `duration` (optional, default `1000` ms); `ttl` (optional auto-expiry in ms, default permanent; invalid optionals fall back to defaults).
- Exhausted queues return `null` on pull until the next window. Broadcasts `ratelimit:set` / `ratelimit:cleared`.

### Set / Clear Concurrency Limit

`PUT /queues/:queue/concurrency` · `DELETE /queues/:queue/concurrency`

```bash
curl -X PUT http://localhost:6790/queues/emails/concurrency \
  -H "Content-Type: application/json" -d '{"concurrency": 5}'
```

Accepts `concurrency` or `limit` (non-numeric rejected). Broadcasts `concurrency:set` / `concurrency:cleared`.

## Stall Detection Configuration

Per-queue recovery for active jobs whose workers crash or miss heartbeats:

`GET /queues/:queue/stall-config` · `PUT /queues/:queue/stall-config`

```bash
curl -X PUT http://localhost:6790/queues/emails/stall-config \
  -H "Content-Type: application/json" \
  -d '{"config": {"enabled": true, "stallInterval": 30000, "maxStalls": 3, "gracePeriod": 5000}}'
```

| Field | Default | Description |
| --- | --- | --- |
| `enabled` | `true` | Enable or disable stall detection. |
| `stallInterval` | `30000` | Mark active job stalled after this many ms without a heartbeat. |
| `maxStalls` | `3` | Move job to DLQ after this many stall recoveries. |
| `gracePeriod` | `5000` | Startup grace window (ms) before stall checks apply. |

Broadcasts `config:stall-changed`.

## Job Groups over HTTP

Pushes via `/queues/:queue/jobs` or `/bulk` support `groupId` (integer `priority` `0..2097151`, FIFO per group). HTTP pulls honor paused groups and manual group rate limits; worker `group.concurrency`/`group.limit` require TCP `PULL`/`PULLB`.

Group management commands (`ListGroups`, `GetGroupInfo`, `GetGroupJobs`, `PauseGroup`, `ResumeGroup`, `RateLimitGroup`, `ClearGroupRateLimit`, `SetGroupPriority`, `DrainGroup`, `RemoveGroup`, and status queries) live in the [TCP Protocol](https://bunqueue.dev/api/tcp/control/#job-groups) and work over [WebSocket `/ws`](https://bunqueue.dev/api/http/realtime-events/#sending-commands).
