feat: make queues durable by default and add seed helpers
This commit is contained in:
@@ -6,11 +6,11 @@ Part of the **WrNexus** framework — an SSR-first, Bun-native full-stack web fr
|
||||
|
||||
## Overview
|
||||
|
||||
`@wrnexus/queue` is a server-side in-process job queue. You register named
|
||||
`@wrnexus/queue` is a server-side durable job queue. You register named
|
||||
workers, enqueue jobs (optionally delayed or recurring), and let the queue poll
|
||||
and run them on a timer — with per-job retry limits and doubling backoff between
|
||||
attempts. The default store lives in memory; the design allows a pluggable driver
|
||||
to back it with Redis/SQL for durability across restarts. Reach for it when you
|
||||
attempts. `defineQueue` persists to `.wrnexus/queue.sqlite` by default, while
|
||||
low-level `createQueue` remains an intentionally in-memory primitive. Reach for it when you
|
||||
need to defer work (emails, webhooks, cleanup) off the request path without a
|
||||
heavyweight external broker. Tests can drive it deterministically via `drain()`.
|
||||
|
||||
@@ -100,6 +100,20 @@ interface Job<T = unknown> {
|
||||
|
||||
## Usage
|
||||
|
||||
Application queues belong in `app/queues/*.ts` and default-export `defineQueue(...)`.
|
||||
Configure persistence once in `wrnexus.config.ts`:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
queue: { storage: "database", databaseName: "default" },
|
||||
// Or omit queue entirely for .wrnexus/queue.sqlite.
|
||||
};
|
||||
```
|
||||
|
||||
Use `storage: "memory"` only for disposable work. A selected database must exist;
|
||||
WrNexus fails startup/first use with a clear error instead of silently falling back.
|
||||
Each job may declare `success(data, job)` and `failed(data, error, job)` lifecycle hooks.
|
||||
|
||||
Register workers, enqueue jobs, then start the poller:
|
||||
|
||||
```ts
|
||||
|
||||
Reference in New Issue
Block a user