@vite-hub/queue 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -12
- package/dist/{client-CwoCdKct.js → client-B8QVg1mA.js} +46 -15
- package/dist/{cloudflare-client-xWteD-su.js → cloudflare-client-BoaOlFzD.js} +13 -8
- package/dist/{cloudflare-resource-name-Bv8Z7nDU.js → cloudflare-resource-name-Coz5CPmn.js} +1 -1
- package/dist/{config-Bzp1xmdh.js → config-ByKUipob.js} +4 -2
- package/dist/{definition-CIiFfst2.js → definition-Dorliu47.js} +9 -2
- package/dist/{duration-C5w_-Rf4.js → duration-CcLSF94z.js} +20 -5
- package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
- package/dist/{error-diagnostics-Dv6nKZQW.js → error-diagnostics-Yj8XCiya.js} +30 -6
- package/dist/{handler-response-CchTXVjm.js → handler-response-GFXYd6mF.js} +6 -2
- package/dist/index.d.ts +13 -8
- package/dist/index.js +4 -4
- package/dist/internal/runtime/cloudflare-client.d.ts +1 -1
- package/dist/internal/runtime/cloudflare-client.js +1 -1
- package/dist/internal/runtime/cloudflare-vite.d.ts +1 -1
- package/dist/internal/runtime/cloudflare-vite.js +9 -8
- package/dist/internal/runtime/local-client.d.ts +3 -3
- package/dist/internal/runtime/local-client.js +4 -4
- package/dist/internal/runtime/postgres-client.d.ts +9 -7
- package/dist/internal/runtime/postgres-client.js +174 -36
- package/dist/internal/runtime/state.d.ts +5 -3
- package/dist/internal/runtime/state.js +1 -1
- package/dist/internal/runtime/vercel-client.d.ts +1 -1
- package/dist/internal/runtime/vercel-client.js +24 -5
- package/dist/internal/runtime/worker-client.d.ts +2 -2
- package/dist/internal/runtime/worker-client.js +1 -1
- package/dist/{local-RX10a_Sq.js → local-BR4W57HU.js} +146 -97
- package/dist/{local-B72WRWkS.d.ts → local-DUh8sGn-.d.ts} +1 -1
- package/dist/{operations-CoEXxfUW.js → operations-COCpSoua.js} +11 -6
- package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-DSslh_vK.d.ts} +169 -1
- package/dist/operations.d.ts +13 -4
- package/dist/operations.js +98 -37
- package/dist/retries-BSAZru9n.js +27 -0
- package/dist/run-handler-B_RVXMs5.js +61 -0
- package/dist/runtime/hosted.d.ts +1 -1
- package/dist/runtime/hosted.js +32 -20
- package/dist/{state-DqxeV11k.js → state-C-t99I4Q.js} +9 -3
- package/dist/{types-BevEYrUV.d.ts → types-BPs6OsRv.d.ts} +1 -1
- package/dist/{types-BzPGPV9z.d.ts → types-rZHAtkK0.d.ts} +74 -12
- package/dist/{vercel-region-DEsR1YJQ.js → vercel-region-Bp3hwRBr.js} +1 -1
- package/dist/vite.d.ts +3 -156
- package/dist/vite.js +460 -68
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ That build proves discovery and generated output only. In the built Worker, `sen
|
|
|
90
90
|
| Cloudflare | The deployed runtime supplies request-scoped Cloudflare Queue bindings | Worker bundle and `wrangler.json` producer and consumer entries | `contentType`, `delay` |
|
|
91
91
|
| Vercel | The deployment runs Vercel Queue callbacks and has a Queue region when the installed SDK requires one | One Nitro route per Queue Definition, with a Vercel queue trigger | `delay`, `idempotencyKey`, `region`, `retention` |
|
|
92
92
|
| Local | One Node server runs the jobs: `node .output/server/index.mjs`, Docker, or a WebContainer | A Nitro plugin that runs stored jobs in the server process | `delay`, `idempotencyKey` |
|
|
93
|
-
| Postgres | One or more Node servers share a Postgres database | A Nitro plugin that starts workers in each server process | `delay`, `idempotencyKey`
|
|
93
|
+
| Postgres | One or more Node servers share a Postgres database | A Nitro plugin that starts workers in each server process | `delay`, `idempotencyKey`, `transaction` |
|
|
94
94
|
|
|
95
95
|
The ViteHub framework host selects Cloudflare for `host: "cloudflare"` and Vercel for `host: "vercel"`. For `host: "node"` and a Nitro `node-server` preset, it selects the postgres driver when the app has a Postgres Default Database, else the local driver. `vitehub({ queue: { driver: "postgres" } })` or `{ driver: "local" }` picks one on Node. Set `driver` explicitly when host inference would be ambiguous. Netlify cannot infer one. ViteHub provides no Queue driver for Deno. Check the [runtime and host support matrix](https://vitehub.dev/docs/frameworks-hosts/support-matrix) before choosing a deployment target.
|
|
96
96
|
|
|
@@ -120,8 +120,8 @@ Direct clients from `createQueueClient()` always redact plain handler errors. Th
|
|
|
120
120
|
|
|
121
121
|
When a production server reopens a dev store, it redacts stored errors without a code before it exposes the jobs. Queue errors and `ViteHubError` keep their code and message.
|
|
122
122
|
|
|
123
|
-
- A failed job runs again after
|
|
124
|
-
- The server writes the attempt count before the handler runs. A job whose handler was running when the process stopped runs again after the restart. If that was the
|
|
123
|
+
- A failed job runs again after the `retries` delay of its Queue Definition: 10, 20, then 40 seconds by default. After `retries.limit` retries (3 by default), or after a Queue error that a retry cannot fix, it becomes a dead job. A dead job stays in its file with the last error. The provider keeps the 100 newest dead jobs of each Queue Definition.
|
|
124
|
+
- The server writes the attempt count before the handler runs. A job whose handler was running when the process stopped runs again after the restart. If that was the last attempt, the job becomes a dead job instead.
|
|
125
125
|
- Delivery is at least once. A successful handler can run again after a restart if the process stops before completion is saved, or if both deleting the job and saving its completed state fail. Make handler side effects idempotent.
|
|
126
126
|
- `delay` survives a restart. `idempotencyKey` returns the message ID of a pending or running job with the same key. A dead job does not hold its key. `sendBatch()` stores all jobs or none.
|
|
127
127
|
- The jobs survive a restart on the same disk. Another host, a new container, or an ephemeral filesystem does not have them. Run one server process per directory: there is no lock between processes, so two processes can run the same job.
|
|
@@ -148,7 +148,9 @@ export default defineConfig({
|
|
|
148
148
|
- The first server creates the table and its indexes under `pg_advisory_xact_lock`, so servers that start at the same time do not race.
|
|
149
149
|
- Workers claim jobs with `UPDATE ... WHERE id IN (SELECT ... FOR UPDATE SKIP LOCKED)`. A send wakes the workers with `NOTIFY`. Without it, each worker checks every second.
|
|
150
150
|
- A claim holds a job for 30 seconds, and a running handler renews it. When a process stops during a handler, another instance runs the job again with the next attempt number after the claim ends.
|
|
151
|
+
- Set `QUEUE_WORKERS=false` on a server process that must send jobs but not run them, such as a web server. The same build then runs as a web server or as a worker. Workers run by default. The startup log and `vitehub queue list` show `workers: false`. Another value than `true` or `false` stops the server with `QUEUE_WORKERS_INVALID`.
|
|
151
152
|
- Retries, dead jobs, `delay`, `idempotencyKey`, `sendBatch()`, and `concurrency` follow the local rules above. `concurrency` applies per process.
|
|
153
|
+
- Await `sendQueue(name, payload, { transaction: tx })` inside a ViteHub Postgres Database transaction on postgres.js or node-postgres. The job rolls back with your changes and runs only after a commit. An ended transaction or one that reaches a different jobs table returns `QUEUE_TRANSACTION_DATABASE_MISMATCH` and saves nothing. Other providers, `vite dev`, the Queue test client, `sendBatch()`, and `deferQueue()` reject `transaction` with `QUEUE_UNSUPPORTED_OPTION`.
|
|
152
154
|
- When Nitro closes, the workers stop taking jobs and wait up to 10 seconds for the running jobs.
|
|
153
155
|
- `vitehub queue list` shows the table and its database without the password, and `durability: "shared"`. `vitehub queue jobs` and the Console read the table, so any instance shows the jobs of all instances.
|
|
154
156
|
- `vite dev` runs the jobs of a postgres app with the local provider and the same rules, so development needs no Postgres.
|
|
@@ -157,17 +159,15 @@ export default defineConfig({
|
|
|
157
159
|
|
|
158
160
|
In `vite dev` and `nuxt dev`, `sendQueue()` stores the job in `.vitehub/data/queue` of the project and the dev server runs the Queue Definition, whatever the provider of the build. A Cloudflare or Vercel app needs no binding, credentials, or `wrangler dev`. The build output does not change: `vite build` still writes the Cloudflare or Vercel runtime.
|
|
159
161
|
|
|
160
|
-
The dev server follows the
|
|
162
|
+
The dev server follows the limits of the provider of the build and the `retries` of each Queue Definition, so a handler fails and retries in dev as it does on the host:
|
|
161
163
|
|
|
162
164
|
| Rule | Cloudflare | Vercel | Local |
|
|
163
165
|
| --- | --- | --- | --- |
|
|
164
|
-
| Attempts | 4 (`max_retries` 3) | No limit until the job expires | 4 |
|
|
165
|
-
| Retry delay | None | 60 seconds (`retryAfterSeconds`) | 1, 2, then 4 seconds |
|
|
166
166
|
| Largest `delay` | `"24h"` (86400 seconds) | `"7d"` (604800 seconds) | No limit |
|
|
167
167
|
| Retention | None | `retention` from `"1m"` to `"7d"`, default `"1d"` | None |
|
|
168
168
|
| Largest payload | 128 KB of JSON | 100 MB of JSON | No limit |
|
|
169
169
|
| Largest `sendBatch()` | 100 jobs, 256 KB | 100 jobs | No limit |
|
|
170
|
-
| Rejected options | `idempotencyKey`, `region`, `retention` | `contentType` | `contentType`, `region`, `retention` |
|
|
170
|
+
| Rejected options | `idempotencyKey`, `region`, `retention`, `transaction` | `contentType`, `transaction` | `contentType`, `region`, `retention`, and `transaction` on local |
|
|
171
171
|
|
|
172
172
|
The sources are the [Cloudflare Queues limits](https://developers.cloudflare.com/queues/platform/limits/), [Cloudflare batching and retries](https://developers.cloudflare.com/queues/configuration/batching-retries/), the [Vercel Queues concepts](https://vercel.com/docs/queues/concepts), and the [Vercel Queues limits](https://vercel.com/docs/queues/pricing#limits). A broken limit fails `sendQueue()` with `QUEUE_PROVIDER_FAILED`, and `error.cause` names the limit. A rejected option fails with `QUEUE_UNSUPPORTED_OPTION` and names the provider of the build.
|
|
173
173
|
|
|
@@ -177,7 +177,7 @@ Dev does not emulate these parts of the host:
|
|
|
177
177
|
- It does not call `onError` or `callbackOptions`. A failed handler retries by the rules above, and a Queue error that a retry cannot fix makes the job dead at once.
|
|
178
178
|
- It keeps a dead job for inspection. Cloudflare deletes it, or moves it to a dead-letter queue, and Vercel deletes an expired job.
|
|
179
179
|
- The payload is a JSON copy. Cloudflare `contentType: "v8"` can send values that JSON cannot, such as a `Map`. The payload size is the JSON size, not the provider encoding.
|
|
180
|
-
- `idempotencyKey` deduplicates only while a job is pending or running. Vercel deduplicates for the retention, up to 24 hours. `useQueue()`
|
|
180
|
+
- `idempotencyKey` deduplicates only while a job is pending or running. Vercel deduplicates for the retention, up to 24 hours. A `useQueue()` client has `provider: "local"`.
|
|
181
181
|
|
|
182
182
|
List, inspect, run again, and remove the stored jobs with the CLI. The commands call the `queue.jobs-list`, `queue.jobs-show`, `queue.jobs-retry`, and `queue.jobs-clear` operations of the running dev server, or of a deployed app with `--url`. The Console and agents run the same operations.
|
|
183
183
|
|
|
@@ -185,10 +185,11 @@ List, inspect, run again, and remove the stored jobs with the CLI. The commands
|
|
|
185
185
|
pnpm vitehub queue jobs list --state dead
|
|
186
186
|
pnpm vitehub queue jobs get <message-id>
|
|
187
187
|
pnpm vitehub queue jobs retry <message-id>
|
|
188
|
+
pnpm vitehub queue jobs retry --queue emails --state dead
|
|
188
189
|
pnpm vitehub queue jobs clear --state dead --yes
|
|
189
190
|
```
|
|
190
191
|
|
|
191
|
-
`--json` prints JSON. `jobs list` takes `--queue` and `--state`. `jobs retry` runs the job now: a dead job gets a new set of attempts, and a delayed job does not wait. `jobs clear` removes pending and dead jobs, not running ones. It asks for confirmation on a terminal and needs `--yes` elsewhere. The handler of a successful job deletes it, so the list shows pending, running, and dead jobs. In `vite dev`, a plain `Error` from a handler shows its message and stack. A production server shows `Queue Delivery failed.` instead, because a message can hold private data; throw a `ViteHubError` to keep a code and message. The same commands work on a Node server with the local or postgres provider. Cloudflare and Vercel do not let the app read their queue, so the commands fail there with `QUEUE_JOBS_UNAVAILABLE`.
|
|
192
|
+
`--json` prints JSON. `jobs list` takes `--queue` and `--state`. `jobs retry` runs the job now: a dead job gets a new set of attempts, and a delayed job does not wait. `jobs retry --queue <name> --state dead` does this for every dead job of the queue, in batches of 500, and returns `{ retried, skipped }`. It skips a dead job when a live job, or a newer dead job, holds its `idempotencyKey`, and `skipped` lists the message IDs of those jobs. `jobs clear` removes pending and dead jobs, not running ones. It asks for confirmation on a terminal and needs `--yes` elsewhere. The handler of a successful job deletes it, so the list shows pending, running, and dead jobs. In `vite dev`, a plain `Error` from a handler shows its message and stack. A production server shows `Queue Delivery failed.` instead, because a message can hold private data; throw a `ViteHubError` to keep a code and message. The same commands work on a Node server with the local or postgres provider. Cloudflare and Vercel do not let the app read their queue, so the commands fail there with `QUEUE_JOBS_UNAVAILABLE`.
|
|
192
193
|
|
|
193
194
|
## Treat acceptance and delivery separately
|
|
194
195
|
|
|
@@ -205,11 +206,15 @@ ViteHub generates the message ID; an `id` option returns `QUEUE_UNSUPPORTED_OPTI
|
|
|
205
206
|
|
|
206
207
|
`deferQueue()` does not wait for provider acceptance. It schedules enqueue work through the current request's `waitUntil`, logs dispatch failures, and calls the Queue Definition's `onDispatchError` hook when present.
|
|
207
208
|
|
|
209
|
+
Set ViteHub's limit for one attempt with `defineQueue({ timeout: "30s", handler })` (default `"15 minutes"`). When ViteHub enforces the limit, `job.signal` aborts and the attempt fails with `QUEUE_JOB_TIMEOUT`, freeing its slot and applying the provider's retry policy. A Vercel function or Cloudflare batch can reach its host limit first, with no abort notification or `QUEUE_JOB_TIMEOUT`. Choose a shorter timeout that leaves time for setup, other messages in the batch, and retry handling. A handler that ignores the signal keeps running and can overlap its retry. Pass `signal` to `fetch()` and other calls.
|
|
210
|
+
|
|
211
|
+
A failed job retries `retries.limit` times (default `3`) after `retries.delay` (default `"10 seconds"`), which doubles after each retry with the default `backoff: "exponential"` and stays the same with `"constant"`. A wait is at most 12 hours. Every provider follows it: Cloudflare through `message.retry({ delaySeconds })` and the consumer's `max_retries`, which the build reads from a number literal in `export default defineQueue({ retries: { limit } })`, Vercel through the retry directive, and local and postgres through the next run time. `defineQueue({ retries: { limit: 10, delay: "30s" }, handler })` keeps a job through an outage of hours.
|
|
212
|
+
|
|
208
213
|
Providers, the local one included, can retry failed delivery, so handlers must tolerate another invocation after a partial side effect. ViteHub does not expose an exactly-once delivery guarantee. Vercel sends an idempotency key, using the generated message ID by default; pass a stable application key when repeated enqueue attempts should share one key. Cloudflare does not accept `idempotencyKey`, so protect non-repeatable side effects inside the handler.
|
|
209
214
|
|
|
210
|
-
On Cloudflare, successful handlers acknowledge the message. Failed handlers retry by default unless the error is a Queue error that a retry cannot fix or `onError` returns an explicit acknowledge or retry action. On Vercel, `callbackOptions.retry` can return an explicit directive
|
|
215
|
+
On Cloudflare, successful handlers acknowledge the message. Failed handlers retry by default unless the error is a Queue error that a retry cannot fix or `onError` returns an explicit acknowledge or retry action. On Vercel, `callbackOptions.retry` can return an explicit directive while retries remain. Returning nothing uses the Queue Definition's delay, capped at 1 hour and shortened if the message expires sooner. ViteHub acknowledges deliveries beyond the attempt limit without calling the handler. Application error codes do not choose retry policy.
|
|
211
216
|
|
|
212
|
-
`sendQueue()`, `dynamicQueue.send()`, `send()`, and `sendBatch()` return `[error, data]`. `error.code` is `QUEUE_PROVIDER_FAILED`, `QUEUE_PROVIDER_INVALID_RESPONSE`,
|
|
217
|
+
`sendQueue()`, `dynamicQueue.send()`, `send()`, and `sendBatch()` return `[error, data]`. `error.code` is `QUEUE_PROVIDER_FAILED`, `QUEUE_PROVIDER_INVALID_RESPONSE`, `QUEUE_TRANSACTION_DATABASE_MISMATCH`, `QUEUE_UNSUPPORTED_OPTION`, or `RUNTIME_DURATION_INVALID`, and each error has `why`, `fix`, `docs`, and `cause`. Configuration errors, for example an unknown Queue name or a missing Cloudflare binding, throw. `JSON.stringify(error)` and Queue delivery reports omit `cause`, so keep credentials and provider responses there. Throw `ViteHubError` from a handler for an application code. See the [Queue error reference](https://vitehub.dev/docs/queue/limits-and-errors) for each code and the retry policy.
|
|
213
218
|
|
|
214
219
|
## Add a Queue from another plugin
|
|
215
220
|
|
|
@@ -263,7 +268,7 @@ The Vite Integration writes `.vitehub/queue.d.ts`. Include that file in your Typ
|
|
|
263
268
|
import { sendQueue, useQueue } from "@vite-hub/queue"
|
|
264
269
|
|
|
265
270
|
const [error] = await sendQueue("welcome-email", { email: "ada@example.com" }, { delay: "1m" })
|
|
266
|
-
const queue =
|
|
271
|
+
const queue = useQueue("welcome-email")
|
|
267
272
|
const [sendError] = await queue.send({ email: "ada@example.com" })
|
|
268
273
|
```
|
|
269
274
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as normalizeQueueOptions } from "./config-
|
|
3
|
-
import {
|
|
4
|
-
import { t as resolveVercelQueueRegion } from "./vercel-region-
|
|
1
|
+
import { _ as resolveWaitUntil, a as getQueueRuntimeEvent, d as runWithQueueRuntimeEvent, i as getQueueRuntimeConfig, l as loadQueueDefinition, n as getOrCreateQueueClient, r as getQueueRuntimeClientFactory, y as getCloudflareEnv } from "./state-C-t99I4Q.js";
|
|
2
|
+
import { n as normalizeQueueOptions } from "./config-ByKUipob.js";
|
|
3
|
+
import { c as queueBatchOptionsError, d as queueUnsupportedOptionsError, i as isQueueError, m as normalizeQueueEnqueueInput, o as normalizePublicQueueIdentifier, r as formatQueueOptionNames, t as readQueueTimes } from "./duration-CcLSF94z.js";
|
|
4
|
+
import { t as resolveVercelQueueRegion } from "./vercel-region-Bp3hwRBr.js";
|
|
5
5
|
import { t as getCloudflareQueueBindingName } from "./cloudflare-BMc35cBD.js";
|
|
6
6
|
import { t as getVercelQueueTopicName } from "./vercel-sUJOxFBB.js";
|
|
7
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
7
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
8
8
|
import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
|
|
9
9
|
// src/runtime/test-client.ts
|
|
10
10
|
/** The sent jobs of the current test. `vite-hub/test` reads the same list. */
|
|
@@ -37,12 +37,12 @@ function createTestQueueClient(test, queue, provider) {
|
|
|
37
37
|
queue,
|
|
38
38
|
async send(payload, options) {
|
|
39
39
|
const input = normalizeQueueEnqueueInput(payload, options);
|
|
40
|
-
const error = queueUnsupportedOptionsError(input.options, provider) ?? readQueueTimes(input.options)[0];
|
|
40
|
+
const error = queueUnsupportedOptionsError(input.options, provider) ?? queueUnsupportedOptionsError(input.options, provider, ["transaction"]) ?? readQueueTimes(input.options)[0];
|
|
41
41
|
if (error) return [error, void 0];
|
|
42
42
|
return [void 0, recordQueueTestMessage(test, queue, input)];
|
|
43
43
|
},
|
|
44
44
|
async sendBatch(items, options = {}) {
|
|
45
|
-
const removed =
|
|
45
|
+
const removed = queueBatchOptionsError(provider, options, items);
|
|
46
46
|
if (removed) return [removed, void 0];
|
|
47
47
|
const inputs = items.map(({ body, ...itemOptions }) => normalizeQueueEnqueueInput(body, {
|
|
48
48
|
...options,
|
|
@@ -112,7 +112,8 @@ async function createNamedQueueClient(name) {
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
|
|
115
|
+
/** Loads the provider QueueClient of a Queue Definition. Config errors, for example an unknown name, throw. */
|
|
116
|
+
async function loadQueueClient(name) {
|
|
116
117
|
const config = getActiveQueueConfig();
|
|
117
118
|
if (config === false) throw queueErrorDiagnostics.QUEUE_DISABLED();
|
|
118
119
|
const definition = await loadNamedQueueDefinition(name);
|
|
@@ -122,19 +123,48 @@ async function useDynamicQueue(name) {
|
|
|
122
123
|
if (definition.cache === false || config.cache === false || config.driver === "cloudflare" || config.driver === "vercel" && resolveVercelQueueRegion(config.region).requestScoped) return await createNamedQueueClient(name);
|
|
123
124
|
return await getOrCreateQueueClient(name, () => createNamedQueueClient(name));
|
|
124
125
|
}
|
|
125
|
-
async function
|
|
126
|
-
let queue;
|
|
126
|
+
async function loadQueueClientForSend(name) {
|
|
127
127
|
try {
|
|
128
|
-
|
|
128
|
+
return [void 0, await loadQueueClient(name)];
|
|
129
129
|
} catch (error) {
|
|
130
130
|
if (isQueueError(error, ["QUEUE_PROVIDER_FAILED"])) return [error, void 0];
|
|
131
131
|
throw error;
|
|
132
132
|
}
|
|
133
|
+
}
|
|
134
|
+
async function sendDynamicQueue(name, payload, options) {
|
|
135
|
+
const [error, queue] = await loadQueueClientForSend(name);
|
|
136
|
+
if (error) return [error, void 0];
|
|
133
137
|
return await queue.send(payload, options);
|
|
134
138
|
}
|
|
139
|
+
async function sendDynamicQueueBatch(name, items, options) {
|
|
140
|
+
const [error, queue] = await loadQueueClientForSend(name);
|
|
141
|
+
if (error) return [error, void 0];
|
|
142
|
+
const sendBatch = queue.sendBatch;
|
|
143
|
+
return await sendBatch(items, options);
|
|
144
|
+
}
|
|
145
|
+
function namedQueueProvider() {
|
|
146
|
+
const config = getQueueRuntimeConfig();
|
|
147
|
+
if (config === false) throw queueErrorDiagnostics.QUEUE_DISABLED();
|
|
148
|
+
if (getViteHubTestMode()) return "local";
|
|
149
|
+
if (!config) throw queueErrorDiagnostics.QUEUE_RUNTIME_NOT_INSTALLED();
|
|
150
|
+
return config.driver;
|
|
151
|
+
}
|
|
152
|
+
function useDynamicQueue(name) {
|
|
153
|
+
return {
|
|
154
|
+
get provider() {
|
|
155
|
+
return namedQueueProvider();
|
|
156
|
+
},
|
|
157
|
+
send: (payload, options) => sendDynamicQueue(name, payload, options),
|
|
158
|
+
sendBatch: (items, options) => sendDynamicQueueBatch(name, items, options)
|
|
159
|
+
};
|
|
160
|
+
}
|
|
135
161
|
function deferDynamicQueue(name, payload, options) {
|
|
136
162
|
const request = getQueueRuntimeEvent();
|
|
137
163
|
const task = async () => {
|
|
164
|
+
if (options && "transaction" in options && options.transaction !== void 0) throw queueErrorDiagnostics.QUEUE_UNSUPPORTED_OPTION({
|
|
165
|
+
options: formatQueueOptionNames(["transaction"]),
|
|
166
|
+
provider: namedQueueProvider()
|
|
167
|
+
});
|
|
138
168
|
const [error] = await runWithQueueRuntimeEvent(request, () => sendDynamicQueue(name, payload, options));
|
|
139
169
|
if (error) throw error;
|
|
140
170
|
};
|
|
@@ -157,10 +187,11 @@ const dynamicQueue = {
|
|
|
157
187
|
use: useDynamicQueue
|
|
158
188
|
};
|
|
159
189
|
/**
|
|
160
|
-
* Returns the
|
|
190
|
+
* Returns the client of a discovered Queue Definition, for `send()` and `sendBatch()`. It loads the provider on the
|
|
191
|
+
* first call. Config errors, for example an unknown name, reject that call.
|
|
161
192
|
*/
|
|
162
|
-
|
|
163
|
-
return
|
|
193
|
+
function useQueue(name) {
|
|
194
|
+
return useDynamicQueue(name);
|
|
164
195
|
}
|
|
165
196
|
/**
|
|
166
197
|
* Sends one job to the Queue and returns `[error, result]`. `error.code` is a `QueueErrorCode`.
|
|
@@ -176,4 +207,4 @@ function sendQueue(name, payload, options) {
|
|
|
176
207
|
function deferQueue(name, payload, options) {
|
|
177
208
|
deferDynamicQueue(name, payload, options);
|
|
178
209
|
}
|
|
179
|
-
export { useQueue as i, dynamicQueue as n,
|
|
210
|
+
export { useQueue as a, sendQueue as i, dynamicQueue as n, loadQueueClient as r, deferQueue as t };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { c as queueBatchOptionsError, d as queueUnsupportedOptionsError, l as queueProviderResult, m as normalizeQueueEnqueueInput, o as normalizePublicQueueIdentifier, t as readQueueTimes, u as queueRemovedOptionsError } from "./duration-CcLSF94z.js";
|
|
2
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
3
3
|
import { n as getCloudflareQueueDefinitionName } from "./cloudflare-BMc35cBD.js";
|
|
4
|
-
import { i as reportQueueDeliveryError, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "./handler-response-
|
|
4
|
+
import { i as reportQueueDeliveryError, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "./handler-response-GFXYd6mF.js";
|
|
5
|
+
import { n as queueRetryPolicy } from "./retries-BSAZru9n.js";
|
|
5
6
|
import { parseDuration } from "@vite-hub/runtime";
|
|
6
7
|
// src/providers/cloudflare.ts
|
|
7
8
|
const cloudflareBindingName = /^[A-Z_]\w{0,127}$/i;
|
|
@@ -48,7 +49,10 @@ function toSendOptions(options = {}) {
|
|
|
48
49
|
delaySeconds: times.delaySeconds
|
|
49
50
|
}];
|
|
50
51
|
}
|
|
51
|
-
function
|
|
52
|
+
function retryWithDelay(message, retries) {
|
|
53
|
+
message.retry({ delaySeconds: Math.ceil(retries.delayMs(typeof message.attempts === "number" ? Math.max(1, message.attempts) : 1) / 1e3) });
|
|
54
|
+
}
|
|
55
|
+
function resolveAction(action, message, fallback, retries) {
|
|
52
56
|
if (action && typeof action === "object" && !Array.isArray(action) && Object.hasOwn(action, "retry")) {
|
|
53
57
|
const removed = queueRemovedOptionsError("cloudflare", action.retry);
|
|
54
58
|
if (removed) throw removed;
|
|
@@ -57,11 +61,12 @@ function resolveAction(action, message, fallback) {
|
|
|
57
61
|
return;
|
|
58
62
|
}
|
|
59
63
|
if ((action === "ack" || action === "retry" ? action : fallback) === "ack") message.ack();
|
|
60
|
-
else message
|
|
64
|
+
else retryWithDelay(message, retries);
|
|
61
65
|
}
|
|
62
66
|
function createCloudflareQueueBatchHandler(options) {
|
|
63
67
|
const requested = Number(options.concurrency ?? 1);
|
|
64
68
|
const concurrency = Number.isFinite(requested) ? Math.max(1, Math.floor(requested)) : 1;
|
|
69
|
+
const retries = queueRetryPolicy(options.retries);
|
|
65
70
|
return async (batch) => {
|
|
66
71
|
const messages = Array.isArray(batch?.messages) ? batch.messages : [];
|
|
67
72
|
if (!messages.length) return;
|
|
@@ -87,10 +92,10 @@ function createCloudflareQueueBatchHandler(options) {
|
|
|
87
92
|
reportQueueDeliveryError(hookError, reportContext);
|
|
88
93
|
}
|
|
89
94
|
try {
|
|
90
|
-
resolveAction(action, message, isNonRetryableQueueError(error) ? "ack" : "retry");
|
|
95
|
+
resolveAction(action, message, isNonRetryableQueueError(error) ? "ack" : "retry", retries);
|
|
91
96
|
} catch (actionError) {
|
|
92
97
|
reportQueueDeliveryError(actionError, reportContext);
|
|
93
|
-
message
|
|
98
|
+
retryWithDelay(message, retries);
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
}
|
|
@@ -118,7 +123,7 @@ function createCloudflareQueueClient(provider) {
|
|
|
118
123
|
return [void 0, { status: "queued" }];
|
|
119
124
|
},
|
|
120
125
|
async sendBatch(items, options) {
|
|
121
|
-
const removed =
|
|
126
|
+
const removed = queueBatchOptionsError("cloudflare", options, items);
|
|
122
127
|
if (removed) return [removed, void 0];
|
|
123
128
|
const messages = [];
|
|
124
129
|
for (const item of items) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as encodeNameHex } from "./cloudflare-BMc35cBD.js";
|
|
2
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
3
3
|
// src/internal/cloudflare-resource-name.ts
|
|
4
4
|
const cloudflareQueueNamePrefix = "queue--";
|
|
5
5
|
const cloudflareQueueNamePattern = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as isRecord } from "./object-DRSmpe04.js";
|
|
2
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
3
3
|
import { defu } from "defu";
|
|
4
4
|
/** Maps a host name or a Nitro preset name, such as `cloudflare-module` or `node-server`, to its ViteHub host. */
|
|
5
5
|
function hostFromNitroPreset(value) {
|
|
@@ -51,6 +51,8 @@ const knownDrivers = /* @__PURE__ */ new Set([
|
|
|
51
51
|
]);
|
|
52
52
|
/** The variable that overrides the connection of the postgres driver at runtime. */
|
|
53
53
|
const postgresQueueUrlVariable = "QUEUE_POSTGRES_URL";
|
|
54
|
+
/** The variable that stops a server process of the postgres driver from running jobs. It still sends them. */
|
|
55
|
+
const queueWorkersVariable = "QUEUE_WORKERS";
|
|
54
56
|
/** Default directory of the local driver, next to the KV `fs-lite` store in `.vitehub/data/kv`. */
|
|
55
57
|
const defaultLocalQueueBase = ".vitehub/data/queue";
|
|
56
58
|
function isLocalHosting(hosting) {
|
|
@@ -97,4 +99,4 @@ function normalizeQueueOptions(options, input = {}) {
|
|
|
97
99
|
if (typeof options !== "undefined" && !isRecord(options)) throw queueErrorDiagnostics.QUEUE_INVALID_CONFIG();
|
|
98
100
|
return resolveDriver(options || {}, normalizeHosting(input.hosting), input.postgresDatabase === true);
|
|
99
101
|
}
|
|
100
|
-
export {
|
|
102
|
+
export { getHostingProvider as a, queueWorkersVariable as i, normalizeQueueOptions as n, resolveHost as o, postgresQueueUrlVariable as r, resolveHostPreset as s, defaultLocalQueueBase as t };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { n as isRecord } from "./object-DRSmpe04.js";
|
|
2
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
3
|
+
import { t as invalidQueueRetries } from "./retries-BSAZru9n.js";
|
|
4
|
+
import { parseDuration } from "@vite-hub/runtime";
|
|
3
5
|
// src/definition.ts
|
|
4
6
|
/** Cloudflare accepts a `max_batch_size` from 1 to 100. */
|
|
5
7
|
function isQueueMaxBatchSize(value) {
|
|
@@ -12,7 +14,9 @@ const queueDefinitionKeys = /* @__PURE__ */ new Set([
|
|
|
12
14
|
"handler",
|
|
13
15
|
"maxBatchSize",
|
|
14
16
|
"onDispatchError",
|
|
15
|
-
"onError"
|
|
17
|
+
"onError",
|
|
18
|
+
"retries",
|
|
19
|
+
"timeout"
|
|
16
20
|
]);
|
|
17
21
|
function defineQueue(definition, ...removed) {
|
|
18
22
|
if (typeof definition === "function" || removed.length) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: "`defineQueue(handler, options)` was removed." });
|
|
@@ -21,6 +25,9 @@ function defineQueue(definition, ...removed) {
|
|
|
21
25
|
if (unknownKey) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: `\`defineQueue()\` does not support the "${unknownKey}" option.` });
|
|
22
26
|
if (!Object.hasOwn(definition, "handler") || typeof definition.handler !== "function") throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: "`defineQueue()` needs a `handler` function." });
|
|
23
27
|
if (definition.maxBatchSize !== void 0 && !isQueueMaxBatchSize(definition.maxBatchSize)) throw queueErrorDiagnostics.QUEUE_MAX_BATCH_SIZE_INVALID({ where: "defineQueue()" });
|
|
28
|
+
const retriesReason = definition.retries === void 0 ? void 0 : invalidQueueRetries(definition.retries);
|
|
29
|
+
if (retriesReason) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: retriesReason });
|
|
30
|
+
if (definition.timeout !== void 0 && !(parseDuration(definition.timeout, "timeout") > 0)) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: "`timeout` must be longer than 0, such as `\"5 minutes\"`." });
|
|
24
31
|
return definition;
|
|
25
32
|
}
|
|
26
33
|
export { isQueueMaxBatchSize as n, defineQueue as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
2
2
|
import { parseDuration, toResultError } from "@vite-hub/runtime";
|
|
3
3
|
import { runtimeErrorDiagnostics } from "@vite-hub/runtime/internal/error-diagnostics";
|
|
4
4
|
// src/enqueue.ts
|
|
@@ -21,19 +21,26 @@ function normalizeQueueEnqueueInput(payload, options = {}) {
|
|
|
21
21
|
const cloudflareUnsupportedEnqueueOptions = [
|
|
22
22
|
"idempotencyKey",
|
|
23
23
|
"region",
|
|
24
|
-
"retention"
|
|
24
|
+
"retention",
|
|
25
|
+
"transaction"
|
|
25
26
|
];
|
|
26
27
|
const localUnsupportedEnqueueOptions = [
|
|
28
|
+
"contentType",
|
|
29
|
+
"region",
|
|
30
|
+
"retention",
|
|
31
|
+
"transaction"
|
|
32
|
+
];
|
|
33
|
+
const postgresUnsupportedEnqueueOptions = [
|
|
27
34
|
"contentType",
|
|
28
35
|
"region",
|
|
29
36
|
"retention"
|
|
30
37
|
];
|
|
31
|
-
const
|
|
38
|
+
const vercelUnsupportedEnqueueOptions = ["contentType", "transaction"];
|
|
32
39
|
const unsupportedEnqueueOptions = {
|
|
33
40
|
cloudflare: cloudflareUnsupportedEnqueueOptions,
|
|
34
41
|
local: localUnsupportedEnqueueOptions,
|
|
35
42
|
postgres: postgresUnsupportedEnqueueOptions,
|
|
36
|
-
vercel:
|
|
43
|
+
vercel: vercelUnsupportedEnqueueOptions
|
|
37
44
|
};
|
|
38
45
|
const removedEnqueueOptions = [
|
|
39
46
|
"delaySeconds",
|
|
@@ -47,6 +54,14 @@ function queueRemovedOptionsError(provider, options, items = []) {
|
|
|
47
54
|
provider
|
|
48
55
|
});
|
|
49
56
|
}
|
|
57
|
+
function queueBatchOptionsError(provider, options, items) {
|
|
58
|
+
const removed = queueRemovedOptionsError(provider, options, items);
|
|
59
|
+
if (removed) return removed;
|
|
60
|
+
if (options && Reflect.get(options, "transaction") !== void 0 || items.some((item) => Reflect.get(item, "transaction") !== void 0)) return queueErrorDiagnostics.QUEUE_UNSUPPORTED_OPTION({
|
|
61
|
+
options: "`transaction`",
|
|
62
|
+
provider
|
|
63
|
+
});
|
|
64
|
+
}
|
|
50
65
|
/** Shared pre-dispatch option validation for provider clients and the test backend. */
|
|
51
66
|
function queueUnsupportedOptionsError(options, provider, names = unsupportedEnqueueOptions[provider]) {
|
|
52
67
|
const unsupported = [...removedEnqueueOptions.filter((option) => Object.hasOwn(options, option)), ...names.filter((option) => options[option] !== void 0)];
|
|
@@ -113,4 +128,4 @@ function readQueueTimes(options, round) {
|
|
|
113
128
|
throw error;
|
|
114
129
|
}
|
|
115
130
|
}
|
|
116
|
-
export {
|
|
131
|
+
export { localUnsupportedEnqueueOptions as a, queueBatchOptionsError as c, queueUnsupportedOptionsError as d, vercelUnsupportedEnqueueOptions as f, isQueueError as i, queueProviderResult as l, normalizeQueueEnqueueInput as m, cloudflareUnsupportedEnqueueOptions as n, normalizePublicQueueIdentifier as o, createQueueMessageId as p, formatQueueOptionNames as r, postgresUnsupportedEnqueueOptions as s, readQueueTimes as t, queueRemovedOptionsError as u };
|
|
@@ -29,7 +29,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
29
29
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
30
30
|
},
|
|
31
31
|
INTERNAL_R0024: {
|
|
32
|
-
fix: "Start the dev server
|
|
32
|
+
fix: "Start the dev server (`nuxt dev` or `vite dev`), or pass `--url <origin>` of a deployed app and set VITEHUB_CONSOLE_PRIVATE_KEY_<NAME> to a private key whose public key the app has in VITEHUB_CONSOLE_KEY_<NAME>.",
|
|
33
33
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
34
34
|
},
|
|
35
35
|
INTERNAL_R0023: {
|
|
@@ -145,7 +145,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
145
145
|
fix: "Give a switch column `format: \"switch\"` and `switch: { operation, input }` with a registered operation name, or remove both."
|
|
146
146
|
},
|
|
147
147
|
INTERNAL_R0025: {
|
|
148
|
-
fix: "Start `vite dev` in the project that you run the command from, or pass `--url` of that server.",
|
|
148
|
+
fix: "Start the dev server (`nuxt dev` or `vite dev`) in the project that you run the command from, or pass `--url` of that server.",
|
|
149
149
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
150
150
|
},
|
|
151
151
|
INTERNAL_R0026: {
|
|
@@ -166,7 +166,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
166
166
|
},
|
|
167
167
|
INTERNAL_R0002: {
|
|
168
168
|
...dynamicError,
|
|
169
|
-
fix:
|
|
169
|
+
fix: ({ fix }) => fix ?? "Build for a host that provides this capability, or set the option named in the message to `false`."
|
|
170
170
|
},
|
|
171
171
|
INTERNAL_R0004: {
|
|
172
172
|
...dynamicError,
|
|
@@ -3,6 +3,10 @@ import { defineErrors } from "@vite-hub/runtime";
|
|
|
3
3
|
const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
4
4
|
docs: "https://vitehub.dev/docs/queue/diagnostics",
|
|
5
5
|
codes: {
|
|
6
|
+
QUEUE_JOB_TIMEOUT: {
|
|
7
|
+
why: ({ queue, timeout }) => `A "${queue}" job ran longer than its timeout of ${timeout}. ViteHub aborted the job's signal and failed this attempt.`,
|
|
8
|
+
fix: "Make the handler finish sooner, or set a longer `timeout` in `defineQueue()`. Pass `job.signal` to `fetch()` and other calls, so they stop when the attempt times out. A handler that ignores the signal keeps running and can overlap the retry."
|
|
9
|
+
},
|
|
6
10
|
QUEUE_PROVIDER_FAILED: {
|
|
7
11
|
why: ({ operation, provider }) => `The ${provider} queue provider failed during ${operation}.`,
|
|
8
12
|
fix: "Read `error.cause` for the provider error. Retry when the provider is available again. Pass `idempotencyKey` on Vercel so that a retry does not enqueue the job two times."
|
|
@@ -11,9 +15,17 @@ const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
|
11
15
|
why: "The Vercel queue provider accepted the job, but returned an invalid `messageId`.",
|
|
12
16
|
fix: "Do not send the job again without an `idempotencyKey`, because the provider can have it. Check the installed `@vercel/queue` version."
|
|
13
17
|
},
|
|
18
|
+
QUEUE_TRANSACTION_DATABASE_MISMATCH: {
|
|
19
|
+
why: ({ reason }) => ({
|
|
20
|
+
database: "The transaction runs on another database or cannot reach the Queue jobs table. ViteHub sent nothing.",
|
|
21
|
+
driver: "`transaction` is not a Drizzle transaction from a ViteHub Postgres Database on postgres.js or node-postgres. ViteHub sent nothing.",
|
|
22
|
+
scope: "The transaction callback has already ended. ViteHub sent nothing."
|
|
23
|
+
})[reason],
|
|
24
|
+
fix: "Await the send inside `db.transaction()` on the ViteHub Database that holds the jobs: the Default Database, or the database of `QUEUE_POSTGRES_URL` when it is set. Pass the callback's `tx` to the send."
|
|
25
|
+
},
|
|
14
26
|
QUEUE_UNSUPPORTED_OPTION: {
|
|
15
27
|
why: ({ options, provider }) => `The ${provider} queue provider does not support the enqueue option ${options}.`,
|
|
16
|
-
fix: ({ options }) => options.includes("Seconds`") ? "Rename `delaySeconds` to `delay` and `retentionSeconds` to `retention`, and write the time as a duration: `{ delay: \"60s\" }` in place of `{ delaySeconds: 60 }`. `vitehub migrate` renames them." : options.includes("`id`") ? "Remove `id`. ViteHub generates the message ID. To deduplicate sends, pass `idempotencyKey` on a provider that supports it." : "Remove the option for this provider. The enqueue options table on the Queue Server API page shows which provider supports each option."
|
|
28
|
+
fix: ({ options }) => options.includes("Seconds`") ? "Rename `delaySeconds` to `delay` and `retentionSeconds` to `retention`, and write the time as a duration: `{ delay: \"60s\" }` in place of `{ delaySeconds: 60 }`. `vitehub migrate` renames them." : options.includes("`id`") ? "Remove `id`. ViteHub generates the message ID. To deduplicate sends, pass `idempotencyKey` on a provider that supports it." : options.includes("`transaction`") ? "Remove `transaction`. Only `sendQueue()` and `send()` on the postgres provider accept it, because they save the job in the same Postgres database. `deferQueue()` sends after the response, when the transaction has ended." : "Remove the option for this provider. The enqueue options table on the Queue Server API page shows which provider supports each option."
|
|
17
29
|
},
|
|
18
30
|
QUEUE_LOCAL_LIMIT_EXCEEDED: {
|
|
19
31
|
why: ({ limit, max, min, provider, value }) => ({
|
|
@@ -41,7 +53,7 @@ const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
|
41
53
|
},
|
|
42
54
|
QUEUE_JOBS_UNAVAILABLE: {
|
|
43
55
|
why: ({ driver }) => `The ${driver} queue driver does not let the app read its jobs. Only the local and postgres drivers store jobs that ViteHub can list.`,
|
|
44
|
-
fix: "Run the app with `vite dev
|
|
56
|
+
fix: "Run the app with its dev server (`nuxt dev` or `vite dev`), which runs every job in the dev server, or on a Node server with the local or postgres driver. Read hosted jobs in the Cloudflare or Vercel dashboard."
|
|
45
57
|
},
|
|
46
58
|
QUEUE_JOB_DUPLICATE: {
|
|
47
59
|
why: "A newer pending or running job has the idempotency key of this dead job, so the dead job cannot run again.",
|
|
@@ -108,8 +120,12 @@ const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
|
108
120
|
fix: ({ database }) => database ? `Set \`connection.url\` on the Database "${database}", or set \`QUEUE_POSTGRES_URL\` on the server to the Postgres URL of the jobs.` : "Add a Default Database with `dialect: 'postgresql'` and build again, or set `QUEUE_POSTGRES_URL` on the server to the Postgres URL of the jobs."
|
|
109
121
|
},
|
|
110
122
|
QUEUE_RUNTIME_NOT_INSTALLED: {
|
|
111
|
-
why: "The Queue runtime
|
|
112
|
-
fix: "
|
|
123
|
+
why: "The Queue runtime is not installed yet. The generated server plugin installs it when the server starts, so code that runs before that plugin cannot send or read `provider`.",
|
|
124
|
+
fix: "Read `provider` and send inside a request handler or a hook, not at the top level of a module or a Nitro plugin. If the error stays, set `queue` in `vitehub()`, or add `hubQueue()` to the Vite plugins when you use `@vite-hub/queue` alone. Then build the app and run the built server."
|
|
125
|
+
},
|
|
126
|
+
QUEUE_VERCEL_LOCAL_BROKER_INVALID: {
|
|
127
|
+
why: "`VERCEL_QUEUE_BASE_URL` selects a local Vercel Queue broker, but the value is not an absolute HTTP or HTTPS URL, or `VERCEL_QUEUE_TOKEN` is not set.",
|
|
128
|
+
fix: "Set both variables to the values of the local broker, as the Vercel CLI does. To send to Vercel Queues, remove `VERCEL_QUEUE_BASE_URL`."
|
|
113
129
|
},
|
|
114
130
|
QUEUE_VERCEL_SDK_INVALID: {
|
|
115
131
|
why: "`@vercel/queue` does not have the client API that ViteHub uses.",
|
|
@@ -119,6 +135,10 @@ const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
|
119
135
|
why: "`@vercel/queue` or `@vercel/functions` cannot be loaded.",
|
|
120
136
|
fix: "Add `@vercel/queue` and `@vercel/functions` to the app dependencies. Read `error.cause` for the import error."
|
|
121
137
|
},
|
|
138
|
+
QUEUE_WORKERS_INVALID: {
|
|
139
|
+
why: "`QUEUE_WORKERS` is set, and its value is not `true` or `false`.",
|
|
140
|
+
fix: "Set `QUEUE_WORKERS=false` on a server process that sends jobs but must not run them, or remove the variable. Workers run by default."
|
|
141
|
+
},
|
|
122
142
|
QUEUE_BINDING_CONFLICT: {
|
|
123
143
|
why: "A custom `queue.binding` works with one Queue Definition only, and this app has more.",
|
|
124
144
|
fix: "Remove `queue.binding`, so that each Queue Definition gets its own generated binding."
|
|
@@ -140,8 +160,8 @@ const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
|
140
160
|
fix: "Rename or remove one of the two Queue Definitions that the message lists. Each Queue name must have one file or one plugin contribution."
|
|
141
161
|
},
|
|
142
162
|
QUEUE_INVALID_CONFIG: {
|
|
143
|
-
why: "
|
|
144
|
-
fix: "
|
|
163
|
+
why: "Queue options must be a plain object or `false`. Only `vitehub()` accepts `queue: true`.",
|
|
164
|
+
fix: "In `vitehub()`, set `queue: true` for the default driver, `queue: { driver: 'cloudflare' }` to choose a driver, or `queue: false` to turn Queue off. Call `hubQueue()` for the default driver in a standalone app, pass a plain object to choose a driver, or pass `false` to turn Queue off."
|
|
145
165
|
},
|
|
146
166
|
QUEUE_INVALID_DEFINITION: {
|
|
147
167
|
why: ({ reason }) => reason,
|
|
@@ -178,6 +198,10 @@ const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
|
178
198
|
QUEUE_RENAMED_PROVIDER_KEY: {
|
|
179
199
|
why: ({ value }) => `\`queue.provider\` is ${value}. ViteHub renamed this key to \`driver\`, and it does not read \`provider\`, so Queue would not use the driver you chose.`,
|
|
180
200
|
fix: ({ value }) => `Set \`queue: { driver: ${value} }\`, or run \`npx @vite-hub/codemods driver-key\` to rename it in every config file.`
|
|
201
|
+
},
|
|
202
|
+
QUEUE_RETRIES_LIMIT_INVALID: {
|
|
203
|
+
why: ({ where }) => `${where}: The Cloudflare build must read the Queue Definition from a default-exported object literal or a direct call to \`defineQueue\`. Set \`retries.limit\` to a whole number from 0 to 100 in that object. The build cannot read variables, spreads, or computed keys in \`retries\`.`,
|
|
204
|
+
fix: "Write `retries` as an object directly in `export default defineQueue({ ... })`, with `limit` as a whole number from 0 to 100, such as `retries: { limit: 5 }`."
|
|
181
205
|
}
|
|
182
206
|
}
|
|
183
207
|
});
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as isQueueError, o as normalizePublicQueueIdentifier } from "./duration-CcLSF94z.js";
|
|
2
2
|
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
3
3
|
import { toResponse } from "@vite-hub/runtime/internal/response";
|
|
4
4
|
// src/internal/delivery-error.ts
|
|
5
|
-
const retryableQueueCodes = /* @__PURE__ */ new Set([
|
|
5
|
+
const retryableQueueCodes = /* @__PURE__ */ new Set([
|
|
6
|
+
"QUEUE_JOB_TIMEOUT",
|
|
7
|
+
"QUEUE_PROVIDER_FAILED",
|
|
8
|
+
"QUEUE_PROVIDER_INVALID_RESPONSE"
|
|
9
|
+
]);
|
|
6
10
|
function isNonRetryableQueueError(error) {
|
|
7
11
|
return isQueueError(error) && !retryableQueueCodes.has(error.code);
|
|
8
12
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as QueueJob, B as QueueSendResult, C as QueueDefinitionOptions, D as QueueEnqueueOptions, E as QueueDriverOptions, F as QueuePayload, G as VercelQueueCallbackOptions, H as ResolvedLocalQueueOptions, I as QueueRegistry, J as VercelQueueRetryDirective, K as VercelQueueClient, L as QueueRetries, M as QueueModuleDriverOptions, N as QueueName, O as QueueErrorCode, P as QueueOptions, Q as VercelQueueSendResult, R as QueueRetryBackoff, S as QueueDefinition, T as QueueDriver, U as ResolvedQueueOptions, V as QueueTransaction, W as VercelQueueBatchSendResult, X as VercelQueueSendBatchMessage, Y as VercelQueueRetryHandler, Z as VercelQueueSendBatchOptions, _ as NodeQueueDriver, a as CloudflareQueueMessageBatch, b as PostgresQueueErrorCode, c as LocalQueueClient, g as NamedQueueClient, i as CloudflareQueueMessage, j as QueueJobStore, k as QueueHandler, l as LocalQueueDriverOptions, m as LocalQueueSendBatchMessage, n as CloudflareQueueClient, o as CloudflareQueueSendBatchItem, p as LocalQueueRules, q as VercelQueueErrorCode, r as CloudflareQueueErrorCode, s as DiscoveredQueueDefinition, t as CloudflareQueueBatchHandlerOptions, u as LocalQueueErrorCode, v as PostgresQueueClient, w as QueueDefinitionRegistry, x as QueueClient, y as PostgresQueueDriverOptions, z as QueueRetryDeadResult } from "./types-rZHAtkK0.js";
|
|
2
2
|
import { Result } from "@vite-hub/runtime";
|
|
3
3
|
/**
|
|
4
4
|
* Defines a Queue from one object: `defineQueue({ handler, concurrency })`. The handler receives one object,
|
|
5
|
-
* `{ payload, id, attempts, metadata }`. The payload type of `handler` types `sendQueue()` for this Queue.
|
|
5
|
+
* `{ payload, id, attempts, metadata, signal }`. The payload type of `handler` types `sendQueue()` for this Queue.
|
|
6
6
|
*/
|
|
7
7
|
export declare function defineQueue<TPayload = unknown, TResult = unknown>(definition: QueueDefinition<TPayload, TResult>): QueueDefinition<TPayload, TResult>;
|
|
8
8
|
export declare function createQueueMessageId(prefix?: string): string;
|
|
9
|
-
declare function useDynamicQueue(name: string): Promise<QueueClient>;
|
|
10
9
|
declare function sendDynamicQueue(name: string, payload: unknown, options?: QueueEnqueueOptions): Promise<Result<QueueSendResult, QueueErrorCode>>;
|
|
11
|
-
declare function
|
|
10
|
+
declare function useDynamicQueue(name: string): NamedQueueClient;
|
|
11
|
+
/** Options of `deferQueue()`. A deferred send runs after the response, when a Database transaction has ended. */
|
|
12
|
+
type QueueDeferOptions = Omit<QueueEnqueueOptions, "transaction"> & {
|
|
13
|
+
transaction?: never;
|
|
14
|
+
};
|
|
15
|
+
declare function deferDynamicQueue(name: string, payload: unknown, options?: QueueDeferOptions): void;
|
|
12
16
|
/** Dispatch externally supplied names and payloads after application validation. */
|
|
13
17
|
export declare const dynamicQueue: {
|
|
14
18
|
defer: typeof deferDynamicQueue;
|
|
@@ -16,9 +20,10 @@ export declare const dynamicQueue: {
|
|
|
16
20
|
use: typeof useDynamicQueue;
|
|
17
21
|
};
|
|
18
22
|
/**
|
|
19
|
-
* Returns the
|
|
23
|
+
* Returns the client of a discovered Queue Definition, for `send()` and `sendBatch()`. It loads the provider on the
|
|
24
|
+
* first call. Config errors, for example an unknown name, reject that call.
|
|
20
25
|
*/
|
|
21
|
-
export declare function useQueue<TName extends QueueName>(name: TName):
|
|
26
|
+
export declare function useQueue<TName extends QueueName>(name: TName): NamedQueueClient<QueueDriver, QueuePayload<TName>>;
|
|
22
27
|
/**
|
|
23
28
|
* Sends one job to the Queue and returns `[error, result]`. `error.code` is a `QueueErrorCode`.
|
|
24
29
|
* Config errors, for example an unknown Queue name, throw.
|
|
@@ -28,6 +33,6 @@ export declare function sendQueue<TName extends QueueName>(name: TName, payload:
|
|
|
28
33
|
* Sends one job after the response, through `waitUntil`. It returns nothing: a failure goes to the log and to the
|
|
29
34
|
* `onDispatchError` option of the Queue Definition. Call `sendQueue()` when the caller needs the message ID.
|
|
30
35
|
*/
|
|
31
|
-
export declare function deferQueue<TName extends QueueName>(name: TName, payload: NoInfer<QueuePayload<TName>>, options?:
|
|
36
|
+
export declare function deferQueue<TName extends QueueName>(name: TName, payload: NoInfer<QueuePayload<TName>>, options?: QueueDeferOptions): void;
|
|
32
37
|
export declare function createQueueClient(options: QueueDriverOptions): Promise<QueueClient>;
|
|
33
|
-
export type { CloudflareQueueBatchHandlerOptions, CloudflareQueueClient, CloudflareQueueErrorCode, CloudflareQueueMessage, CloudflareQueueMessageBatch, CloudflareQueueSendBatchItem, DiscoveredQueueDefinition, LocalQueueClient, LocalQueueDriverOptions, LocalQueueErrorCode, LocalQueueRules, LocalQueueSendBatchMessage, NodeQueueDriver, PostgresQueueClient, PostgresQueueDriverOptions, PostgresQueueErrorCode, QueueClient, QueueDefinition, QueueDefinitionOptions, QueueDefinitionRegistry, QueueDriver, QueueDriverOptions, QueueEnqueueOptions, QueueErrorCode, QueueHandler, QueueJob, QueueJobStore, QueueModuleDriverOptions, QueueName, QueueOptions, QueuePayload, QueueRegistry, QueueSendResult, ResolvedLocalQueueOptions, ResolvedQueueOptions, VercelQueueBatchSendResult, VercelQueueCallbackOptions, VercelQueueClient, VercelQueueErrorCode, VercelQueueRetryDirective, VercelQueueRetryHandler, VercelQueueSendBatchMessage, VercelQueueSendBatchOptions, VercelQueueSendResult };
|
|
38
|
+
export type { CloudflareQueueBatchHandlerOptions, CloudflareQueueClient, CloudflareQueueErrorCode, CloudflareQueueMessage, CloudflareQueueMessageBatch, CloudflareQueueSendBatchItem, DiscoveredQueueDefinition, LocalQueueClient, LocalQueueDriverOptions, LocalQueueErrorCode, LocalQueueRules, LocalQueueSendBatchMessage, NamedQueueClient, NodeQueueDriver, PostgresQueueClient, PostgresQueueDriverOptions, PostgresQueueErrorCode, QueueClient, QueueDeferOptions, QueueDefinition, QueueDefinitionOptions, QueueDefinitionRegistry, QueueDriver, QueueDriverOptions, QueueEnqueueOptions, QueueErrorCode, QueueHandler, QueueJob, QueueJobStore, QueueModuleDriverOptions, QueueName, QueueOptions, QueuePayload, QueueRegistry, QueueRetries, QueueRetryBackoff, QueueRetryDeadResult, QueueSendResult, QueueTransaction, ResolvedLocalQueueOptions, ResolvedQueueOptions, VercelQueueBatchSendResult, VercelQueueCallbackOptions, VercelQueueClient, VercelQueueErrorCode, VercelQueueRetryDirective, VercelQueueRetryHandler, VercelQueueSendBatchMessage, VercelQueueSendBatchOptions, VercelQueueSendResult };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as defineQueue } from "./definition-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as defineQueue } from "./definition-Dorliu47.js";
|
|
2
|
+
import { p as createQueueMessageId } from "./duration-CcLSF94z.js";
|
|
3
|
+
import { a as useQueue, i as sendQueue, n as dynamicQueue, t as deferQueue } from "./client-B8QVg1mA.js";
|
|
4
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
5
5
|
// src/runtime/create-client.ts
|
|
6
6
|
async function createQueueClient(options) {
|
|
7
7
|
if (options.driver === void 0 && Object.hasOwn(options, "provider")) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as QueueDriverOptions, x as QueueClient } from "../../types-rZHAtkK0.js";
|
|
2
2
|
export declare function createCloudflareQueueRuntimeClient(options: QueueDriverOptions): Promise<QueueClient>;
|