Memory Queue
Memory Queue processes jobs in the same Node.js process without an external queue backend. The memory provider requires no cloud accounts, SDKs, or infrastructure. ViteHub stores jobs in an in-memory array and processes them automatically when enqueued.
Before you start
Install @vitehub/queue. The memory provider has no additional dependencies.
pnpm add https://pkg.pr.new/nuxt-hub/agent/@vitehub/queue@main
Configure Memory
export default defineNuxtConfig({
modules: ['@vitehub/queue/nuxt'],
queue: {
provider: 'memory',
},
})
provider field entirely in development.Define a queue
import { defineQueue } from '@vitehub/queue'
export default defineQueue(async (job) => {
console.log('Processing:', job.payload)
return { processed: true }
})
How auto-processing works
When runQueue() enqueues a message with the memory provider, ViteHub automatically fires the queue handler in a microtask. The handler runs asynchronously after the current request completes, so runQueue() returns immediately without waiting for the handler to finish.
import { runQueue } from '@vitehub/queue'
export default defineEventHandler(async () => {
// Returns immediately — handler runs in the background
return runQueue('welcome-email', {
id: `email-${Date.now()}`,
payload: { to: 'user@example.com' },
})
})
Errors from the handler are caught and logged to the console. Errors do not propagate to the caller or trigger retries.
Provider-specific methods
The memory provider exposes additional methods through getQueue() for inspecting and manually draining the message store.
import { getQueue } from '@vitehub/queue'
export default defineEventHandler(async () => {
const queue = await getQueue('welcome-email')
return {
size: queue.memory.size(),
next: queue.memory.peek(3),
}
})
| Method | Description |
|---|---|
size() | Returns the number of messages in the store. |
peek(limit?) | Returns up to limit messages without removing them. |
drain(handler) | Shifts messages off the store one by one, calling handler for each. Returns the count of messages processed. |
What changes on Memory
| Concern | Behavior |
|---|---|
| Storage | In-process array. Messages are lost when the server restarts. |
| Processing | Automatic via microtask after runQueue(). No separate worker needed. |
| Retries | None. Failed jobs log an error and are not retried. |
| Message IDs | Generated as mem_<uuid> with a timestamp fallback. |