# Queue hosts

## Develop locally

`pnpm dev` runs Queue jobs in the dev server for every preset. `sendQueue()` stores the job in `.vitehub/data/queue`, and the dev server runs your queue file. Cloudflare and Vercel apps need no binding or credentials. Dev follows the retry, delay, and size rules of the build's provider, so a handler fails and retries as on the host. See [Dev delivery](https://vitehub.dev/docs/queue/limits-and-errors#dev-delivery) for the rules and gaps.

```bash [Terminal]
pnpm vitehub queue list
pnpm vitehub queue jobs list
pnpm vitehub queue jobs show <message-id>
pnpm vitehub queue jobs retry <message-id>
pnpm vitehub queue jobs clear --state dead --yes
```

- `queue list` shows `provider: "local"`, the job folder, `durability: "single-host"`, `deadLimit` (dead jobs kept per queue), and the pending, running, and dead jobs of each queue. In a Cloudflare or Vercel app, also `rules`, the build's provider.
- `queue jobs list` shows each stored job with its attempts and last error. `queue jobs show` adds the payload.
- `queue jobs retry` runs a job now. A dead job gets new attempts.
- `queue jobs clear` removes pending and dead jobs. It asks to confirm on a terminal and needs `--yes` elsewhere.

Each command takes `--json`, and `--url` for a deployed app. The Console and agents run the same `queue.jobs-*` operations.

With `preset: 'node'`, the built server also uses the local provider, in Docker and in a StackBlitz WebContainer too. Jobs survive a restart on the same disk. In Docker, mount `.vitehub/data` as a volume, or a new container loses them. Run one server process per folder. [Local delivery](https://vitehub.dev/docs/queue/limits-and-errors#local-delivery) lists the retry and dead-job rules.

For Cloudflare or Vercel, build to check the Nitro output. A plain Node process, such as a `tsx` script, skips Vite discovery and the generated registry, so `sendQueue()` finds no queue files there.

```bash [Terminal]
pnpm add vite-hub @vite-hub/queue
pnpm vite build
pnpm vitehub inspect definitions --kind queue
```

The build writes `.vitehub/queue/registry.mjs`. `vitehub inspect definitions` lists the queues that ViteHub found. Then check the Nitro output of your provider.

| Provider | Output to inspect |
| --- | --- |
| Cloudflare | `.output/server/wrangler.json` queue producers and consumers. |
| Vercel | `.vercel/output/functions/api/vitehub/queues/vercel/<name>.func/.vc-config.json` queue triggers. |

To typecheck generated Queue files on Vercel, set `lib: ['DOM', 'ESNext']` and `types: ['node']` in `tsconfig.json`.

For fast unit tests, test the code your handler calls. `pnpm dev` tests sending and delivery together with the provider's rules. To test the provider itself, run the built Worker with `wrangler dev`, or deploy.

## Host output

Nitro is the only host output. The Queue package finds your queues, generates a registry, and adds delivery to the Nitro config.

| Provider | Output |
| --- | --- |
| Cloudflare | `wrangler.json` queue producers and consumers. Nitro's `cloudflare:queue` hook runs the consumer. |
| Vercel | One Nitro route per queue under `/api/vitehub/queues/vercel/`. `vercel.functionRules` gives each route its queue trigger, so Nitro writes one function per queue. |
| Local | The Queue Nitro plugin. It reads `.vitehub/data/queue` at server start and runs due jobs. `pnpm dev` uses it for every provider. The build keeps the output above. |

Do not import generated files in app code.

## Preview deployments

- A Cloudflare Version URL uses the production resources of its Worker version, so it sends to **production queues** ([Compare workflows](https://developers.cloudflare.com/workers/previews/compare-workflows/)).
- Two Cloudflare Previews that bind one queue name send to the same queue ([Resources and isolation](https://developers.cloudflare.com/workers/previews/resources/)).
- For a Preview, declare queue producers in `previews.queues.producers` of your Wrangler config. ViteHub does not write that block, and Cloudflare accepts no consumers there ([Previews configuration](https://developers.cloudflare.com/workers/previews/configuration/)).
- For a separate preview Worker, set `queue.namePrefix` in its build.

Read [Preview deployments share data](https://vitehub.dev/docs/development/provisioning#preview-deployments-share-data).

<!-- vitehub-docs:section-links -->
## In this section

- [Overview](https://vitehub.dev/raw/docs/queue.md)
- [Get started](https://vitehub.dev/raw/docs/queue/get-started.md)
- [Configure](https://vitehub.dev/raw/docs/queue/configure.md)
- [Server API](https://vitehub.dev/raw/docs/queue/server-api.md)
- [Hosts](https://vitehub.dev/raw/docs/queue/hosts.md) (this page)
- [Limits and errors](https://vitehub.dev/raw/docs/queue/limits-and-errors.md)
- [Concepts](https://vitehub.dev/raw/docs/queue/concepts.md)

Next: [QUEUE_DISABLED](https://vitehub.dev/raw/docs/queue/diagnostics/queue_disabled.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
