@vite-hub/queue 0.1.0 → 0.4.1
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 +152 -29
- package/dist/client-B53_G4ky.js +182 -0
- package/dist/{cloudflare-client-COzQ8fHk.js → cloudflare-client-CoISDpIx.js} +28 -21
- package/dist/{cloudflare-resource-name-CCuLDvSP.js → cloudflare-resource-name-BIfBglC2.js} +1 -1
- package/dist/config-B2eaXaT5.js +105 -0
- package/dist/durability.d.ts +13 -0
- package/dist/durability.js +47 -0
- package/dist/duration-tujyhAKt.js +111 -0
- package/dist/error-diagnostics-CQ4BUqRe.js +270 -0
- package/dist/error-diagnostics-mJXBjmQx.js +181 -0
- package/dist/{handler-response-CBwIkmTS.js → handler-response-B6lz9nCn.js} +9 -4
- package/dist/index.d.ts +20 -32
- package/dist/index.js +39 -17
- package/dist/internal/runtime/cloudflare-client.d.ts +2 -2
- package/dist/internal/runtime/cloudflare-client.js +1 -1
- package/dist/internal/runtime/cloudflare-vite.d.ts +30 -2
- package/dist/internal/runtime/cloudflare-vite.js +111 -1
- package/dist/internal/runtime/local-client.d.ts +17 -0
- package/dist/internal/runtime/local-client.js +71 -0
- package/dist/internal/runtime/postgres-client.d.ts +46 -0
- package/dist/internal/runtime/postgres-client.js +570 -0
- package/dist/internal/runtime/state.d.ts +11 -4
- package/dist/internal/runtime/state.js +2 -2
- package/dist/internal/runtime/vercel-client.d.ts +2 -2
- package/dist/internal/runtime/vercel-client.js +66 -28
- package/dist/internal/runtime/worker-client.d.ts +6 -0
- package/dist/internal/runtime/worker-client.js +11 -0
- package/dist/invariant-D8_xBqmZ.js +22 -0
- package/dist/local-CUaWoRUx.d.ts +23 -0
- package/dist/local-Di0FrVUw.js +553 -0
- package/dist/object-D8pRdprI.js +15 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
- package/dist/operations-BVV-9Q0N.js +129 -0
- package/dist/operations.d.ts +47 -9
- package/dist/operations.js +186 -69
- package/dist/runtime/hosted.d.ts +3 -5
- package/dist/runtime/hosted.js +21 -45
- package/dist/{state-G9s378-e.js → state-DLqTqF6V.js} +59 -47
- package/dist/types-CiuSIPR0.d.ts +440 -0
- package/dist/types-Dsbb_Pvp.d.ts +10 -0
- package/dist/vercel-region-B95MAMXN.js +26 -0
- package/dist/virtual.d.ts +4 -0
- package/dist/vite.d.ts +366 -49
- package/dist/vite.js +2071 -2
- package/package.json +39 -46
- package/dist/client-CIc3jsj2.js +0 -114
- package/dist/cloudflare-vite-BCuJOXcT.js +0 -111
- package/dist/cloudflare-vite-CjdP5yBN.d.ts +0 -29
- package/dist/config-BINujLv4.js +0 -74
- package/dist/enqueue-CnQ0QR3O.js +0 -22
- package/dist/error-diagnostics-A_8Kp-48.js +0 -116
- package/dist/error-diagnostics-qzRF6IVB.js +0 -109
- package/dist/errors-DIFaM9tW.js +0 -42
- package/dist/nuxt.d.ts +0 -39
- package/dist/nuxt.js +0 -34
- package/dist/object-B1NW521B.js +0 -7
- package/dist/operations-Cnjbz8kk.js +0 -63
- package/dist/types-1GRMYES1.d.ts +0 -180
- package/dist/vercel-region-cjskrOKl.js +0 -122
- package/dist/vite-ChWLzOVu.js +0 -1512
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { defineErrors } from "@vite-hub/runtime";
|
|
2
|
+
//#region src/error-diagnostics.ts
|
|
3
|
+
const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
4
|
+
docs: "https://vitehub.dev/docs/queue/diagnostics",
|
|
5
|
+
codes: {
|
|
6
|
+
QUEUE_PROVIDER_FAILED: {
|
|
7
|
+
why: ({ operation, provider }) => `The ${provider} queue provider failed during ${operation}.`,
|
|
8
|
+
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."
|
|
9
|
+
},
|
|
10
|
+
QUEUE_PROVIDER_INVALID_RESPONSE: {
|
|
11
|
+
why: "The Vercel queue provider accepted the job, but returned an invalid `messageId`.",
|
|
12
|
+
fix: "Do not send the job again without an `idempotencyKey`, because the provider can have it. Check the installed `@vercel/queue` version."
|
|
13
|
+
},
|
|
14
|
+
QUEUE_UNSUPPORTED_OPTION: {
|
|
15
|
+
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."
|
|
17
|
+
},
|
|
18
|
+
QUEUE_LOCAL_LIMIT_EXCEEDED: {
|
|
19
|
+
why: ({ limit, max, min, provider, value }) => ({
|
|
20
|
+
"batch-bytes": `${provider} accepts up to ${max} bytes in one \`sendBatch()\`, got ${value} bytes of JSON.`,
|
|
21
|
+
"batch-empty": "Vercel requires at least one job in a `sendBatch()`.",
|
|
22
|
+
"batch-jobs": `${provider} accepts up to ${max} jobs in one \`sendBatch()\`, got ${value}.`,
|
|
23
|
+
"delay": `\`delay\` must be a time from 0, got ${value} seconds.`,
|
|
24
|
+
"delay-max": `${provider} accepts a \`delay\` of up to ${max} seconds, got ${value} seconds.`,
|
|
25
|
+
"payload": `${provider} accepts a payload of up to ${max} bytes, got ${value} bytes of JSON.`,
|
|
26
|
+
"retention": `${provider} accepts a \`retention\` from ${min} to ${max} seconds, got ${value} seconds.`
|
|
27
|
+
})[limit],
|
|
28
|
+
fix: "Change the job as the message says: `delay`, `retention`, the payload size, or the number or size of the jobs in one `sendBatch()`. The local provider applies the limits of the production provider, so the same job fails there too."
|
|
29
|
+
},
|
|
30
|
+
QUEUE_VERCEL_BATCH_REJECTED: {
|
|
31
|
+
why: ({ failed, total }) => `@vercel/queue did not accept ${failed} of ${total} batch messages.`,
|
|
32
|
+
fix: "Read `results` on this error for the result of each job. Send the failed jobs again with the same `idempotencyKey`, so that Vercel does not enqueue an accepted job two times."
|
|
33
|
+
},
|
|
34
|
+
QUEUE_VERCEL_SEND_BATCH_UNAVAILABLE: {
|
|
35
|
+
why: "The Vercel queue client has no `sendBatch()`. Install `@vercel/queue` 0.10 or later.",
|
|
36
|
+
fix: "Install `@vercel/queue` 0.10 or later, for example with `pnpm add @vercel/queue@latest`. Or pass a `client` that has `sendBatch()`."
|
|
37
|
+
},
|
|
38
|
+
QUEUE_DEFINITION_NAME_INVALID: {
|
|
39
|
+
why: "The queue name is not a valid Queue Definition name.",
|
|
40
|
+
fix: "Pass the name of a Queue Definition. `vitehub queue list` shows them."
|
|
41
|
+
},
|
|
42
|
+
QUEUE_JOBS_UNAVAILABLE: {
|
|
43
|
+
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`, 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
|
+
},
|
|
46
|
+
QUEUE_JOB_DUPLICATE: {
|
|
47
|
+
why: "A newer pending or running job has the idempotency key of this dead job, so the dead job cannot run again.",
|
|
48
|
+
fix: "Wait for the newer job to end, or remove the dead job with `vitehub queue jobs clear --state dead`."
|
|
49
|
+
},
|
|
50
|
+
QUEUE_JOB_NOT_FOUND: {
|
|
51
|
+
why: "No stored job has this message ID. The local and postgres drivers delete a job when its handler succeeds.",
|
|
52
|
+
fix: "Run `vitehub queue jobs list` for the IDs of the pending, running, and dead jobs."
|
|
53
|
+
},
|
|
54
|
+
QUEUE_JOB_RUNNING: {
|
|
55
|
+
why: "The job is running now.",
|
|
56
|
+
fix: "Wait for the attempt to end, then run `vitehub queue jobs show` for its state."
|
|
57
|
+
},
|
|
58
|
+
QUEUE_BINDING_NOT_FOUND: {
|
|
59
|
+
why: ({ binding }) => binding ? `The Cloudflare queue binding "${binding}" is not in the Worker env.` : "The Cloudflare queue client has no binding.",
|
|
60
|
+
fix: "Run the Worker that `vite build` writes, with `wrangler dev` or a deployment, so its configuration has the generated binding. A custom Worker configuration must keep that binding. `vite dev` runs Queue jobs in the dev server and needs no binding."
|
|
61
|
+
},
|
|
62
|
+
QUEUE_DEFINITION_LOAD_FAILED: {
|
|
63
|
+
why: ({ queue }) => queue ? `The Queue Definition "${queue}" failed to load.` : "A Queue Definition failed to load.",
|
|
64
|
+
fix: "Read `error.cause` for the import error, and fix the Queue Definition module."
|
|
65
|
+
},
|
|
66
|
+
QUEUE_DEFINITION_NOT_FOUND: {
|
|
67
|
+
why: ({ queue }) => queue ? `No Queue Definition has the name "${queue}".` : "No Queue Definition has the requested name.",
|
|
68
|
+
fix: "Add `server/queues/<name>.ts` with a default `defineQueue()` export, and build again with Queue enabled. The generated server output loads the Queue Definitions, so a script that runs outside of it, or an app built without Queue, finds none."
|
|
69
|
+
},
|
|
70
|
+
QUEUE_DISABLED: {
|
|
71
|
+
why: "Queue is disabled in this runtime.",
|
|
72
|
+
fix: "In `vitehub()`, set `queue.driver` to the driver of the host, or remove `driver`. With `@vite-hub/queue` alone, do not pass `false` to `hubQueue()`, and set a `driver` that matches the host."
|
|
73
|
+
},
|
|
74
|
+
QUEUE_DRIVER_MISMATCH: {
|
|
75
|
+
why: ({ driver, expected }) => `The ${expected} Queue runtime received the ${driver} driver.`,
|
|
76
|
+
fix: "Set `queue.driver` to the driver of the deployment preset, and build again."
|
|
77
|
+
},
|
|
78
|
+
QUEUE_INVALID_BINDING: {
|
|
79
|
+
why: "The Cloudflare queue binding does not have `send()` and `sendBatch()`.",
|
|
80
|
+
fix: "Pass a Cloudflare Queue producer binding, for example `env.WELCOME_QUEUE`."
|
|
81
|
+
},
|
|
82
|
+
QUEUE_MISSING_REGION: {
|
|
83
|
+
why: "The installed `@vercel/queue` needs a region, and ViteHub cannot find one.",
|
|
84
|
+
fix: "Set `queue.region` in the Vite config, or set the `QUEUE_REGION` environment variable."
|
|
85
|
+
},
|
|
86
|
+
QUEUE_MISSING_QUEUE: {
|
|
87
|
+
why: "A direct local queue client needs a `queue` name.",
|
|
88
|
+
fix: "Pass the name of a Queue Definition as `queue` to `createQueueClient()`, or use `useQueue()`."
|
|
89
|
+
},
|
|
90
|
+
QUEUE_LOCAL_MODE_MISMATCH: {
|
|
91
|
+
why: "The local Queue directory already has an engine with a different development error disclosure mode.",
|
|
92
|
+
fix: "Use `useQueue()` in the generated server runtime, or give the direct client a separate directory."
|
|
93
|
+
},
|
|
94
|
+
QUEUE_MISSING_TOPIC: {
|
|
95
|
+
why: "A direct Vercel queue client needs a `topic`.",
|
|
96
|
+
fix: "Pass `topic` to `createQueueClient()`, or use `useQueue()` for a discovered Queue Definition."
|
|
97
|
+
},
|
|
98
|
+
QUEUE_POSTGRES_CLOSING: {
|
|
99
|
+
why: "The Postgres Queue runtime is shutting down and cannot accept more jobs or connections.",
|
|
100
|
+
fix: "Send jobs before server shutdown starts, or send them from another running instance."
|
|
101
|
+
},
|
|
102
|
+
QUEUE_POSTGRES_INVALID_URL: {
|
|
103
|
+
why: ({ variable }) => `${variable} is set, and its value is not a \`postgres://\` or \`postgresql://\` URL.`,
|
|
104
|
+
fix: "Set `QUEUE_POSTGRES_URL` to the Postgres URL of the jobs, or remove it to use the connection of the Default Database."
|
|
105
|
+
},
|
|
106
|
+
QUEUE_POSTGRES_MISSING_CONNECTION: {
|
|
107
|
+
why: ({ database }) => database ? `The postgres queue provider uses the connection of the Database "${database}", and that Database has no Postgres client in this runtime.` : "The postgres queue provider has no connection: the build found no Postgres Default Database, and `QUEUE_POSTGRES_URL` is not set.",
|
|
108
|
+
fix: "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
|
+
},
|
|
110
|
+
QUEUE_RUNTIME_NOT_INSTALLED: {
|
|
111
|
+
why: "The Queue runtime has no client factory. The generated server output installs it.",
|
|
112
|
+
fix: "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."
|
|
113
|
+
},
|
|
114
|
+
QUEUE_VERCEL_SDK_INVALID: {
|
|
115
|
+
why: "`@vercel/queue` does not have the client API that ViteHub uses.",
|
|
116
|
+
fix: "Install a supported `@vercel/queue` version, or pass a `client` that has `send()` and `handleCallback()`."
|
|
117
|
+
},
|
|
118
|
+
QUEUE_VERCEL_SDK_UNAVAILABLE: {
|
|
119
|
+
why: "`@vercel/queue` or `@vercel/functions` cannot be loaded.",
|
|
120
|
+
fix: "Add `@vercel/queue` and `@vercel/functions` to the app dependencies. Read `error.cause` for the import error."
|
|
121
|
+
},
|
|
122
|
+
QUEUE_BINDING_CONFLICT: {
|
|
123
|
+
why: "A custom `queue.binding` works with one Queue Definition only, and this app has more.",
|
|
124
|
+
fix: "Remove `queue.binding`, so that each Queue Definition gets its own generated binding."
|
|
125
|
+
},
|
|
126
|
+
QUEUE_CONTRIBUTION_INVALID: {
|
|
127
|
+
why: ({ message }) => message,
|
|
128
|
+
fix: "Correct the `vitehub.queues` entry of the plugin that the message names. Give it a `name` and `definition: { module }`, where `module` is the absolute path or `file:` URL of a file with `export default defineQueue(...)`."
|
|
129
|
+
},
|
|
130
|
+
QUEUE_CRYPTO_UNAVAILABLE: {
|
|
131
|
+
why: "Cloudflare queue names for long Queue Definition names need the `node:crypto` module, and this runtime does not have it.",
|
|
132
|
+
fix: "Enable the `nodejs_compat` compatibility flag, or use a shorter Queue Definition name."
|
|
133
|
+
},
|
|
134
|
+
QUEUE_DEFINITIONS_CHANGED: {
|
|
135
|
+
why: ({ context }) => `The ${context} Queue Definitions changed after Vite resolved the config.`,
|
|
136
|
+
fix: "Generate Queue Definition files before the Vite config resolves, then build again."
|
|
137
|
+
},
|
|
138
|
+
QUEUE_DEFINITION_DUPLICATE: {
|
|
139
|
+
why: ({ message }) => message,
|
|
140
|
+
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
|
+
},
|
|
142
|
+
QUEUE_INVALID_CONFIG: {
|
|
143
|
+
why: "`queue` must be a plain object or `false`.",
|
|
144
|
+
fix: "Pass an object, for example `queue: { driver: 'cloudflare' }`."
|
|
145
|
+
},
|
|
146
|
+
QUEUE_INVALID_DEFINITION: {
|
|
147
|
+
why: ({ reason }) => reason,
|
|
148
|
+
fix: "Pass one object with a `handler` function and the options next to it, for example `defineQueue({ handler: async ({ payload }) => { ... }, concurrency: 2 })`. Run `npx vitehub migrate` to move the former `defineQueue(handler, options)` form."
|
|
149
|
+
},
|
|
150
|
+
QUEUE_INVALID_DRIVER: {
|
|
151
|
+
why: ({ driver }) => `\`queue.driver\` "${driver}" is not a Queue driver.`,
|
|
152
|
+
fix: "Set `queue.driver` to \"cloudflare\", \"vercel\", \"local\", or \"postgres\"."
|
|
153
|
+
},
|
|
154
|
+
QUEUE_INVALID_NAME: {
|
|
155
|
+
why: ({ name }) => `The Cloudflare queue name "${name}" can contain only letters, numbers, and dashes, and must start and end with a letter or number.`,
|
|
156
|
+
fix: "Change `queue.namePrefix` so that it contains only letters, numbers, and dashes."
|
|
157
|
+
},
|
|
158
|
+
QUEUE_MISSING_DRIVER: {
|
|
159
|
+
why: ({ hosting }) => `ViteHub cannot select a Queue driver for ${hosting} hosting.`,
|
|
160
|
+
fix: "Set `queue.driver`, select the Cloudflare, Vercel, or Node deployment preset, or set `queue: false`."
|
|
161
|
+
},
|
|
162
|
+
QUEUE_NAME_COLLISION: {
|
|
163
|
+
why: ({ first, resolved, second }) => `The Queue Definitions "${first}" and "${second}" have the same provider name "${resolved}".`,
|
|
164
|
+
fix: "Rename one of the two Queue Definition files."
|
|
165
|
+
},
|
|
166
|
+
QUEUE_PLUGIN_INCOMPATIBLE: {
|
|
167
|
+
why: "The `hubQueue()` plugin in the Vite config does not expose the Queue Nitro config.",
|
|
168
|
+
fix: "Install one version of `@vite-hub/queue`, and use `hubQueue()` from it."
|
|
169
|
+
},
|
|
170
|
+
QUEUE_PROVISION_FAILED: {
|
|
171
|
+
why: "Cloudflare returned an invalid queue list during provisioning.",
|
|
172
|
+
fix: "Run `vitehub provision run --host cloudflare --dry-run` again, and check the Cloudflare token permissions."
|
|
173
|
+
},
|
|
174
|
+
QUEUE_RENAMED_PROVIDER_KEY: {
|
|
175
|
+
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.`,
|
|
176
|
+
fix: ({ value }) => `Set \`queue: { driver: ${value} }\`, or run \`npx @vite-hub/codemods driver-key\` to rename it in every config file.`
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
//#endregion
|
|
181
|
+
export { queueErrorDiagnostics as t };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as normalizePublicQueueIdentifier, r as isQueueError } from "./duration-tujyhAKt.js";
|
|
2
2
|
import { getViteHubErrorShape, toResponse } from "@vite-hub/runtime";
|
|
3
3
|
//#region src/internal/delivery-error.ts
|
|
4
4
|
const retryableQueueCodes = /* @__PURE__ */ new Set(["QUEUE_PROVIDER_FAILED", "QUEUE_PROVIDER_INVALID_RESPONSE"]);
|
|
5
5
|
function isNonRetryableQueueError(error) {
|
|
6
6
|
return isQueueError(error) && !retryableQueueCodes.has(error.code);
|
|
7
7
|
}
|
|
8
|
-
function toReportError(error) {
|
|
8
|
+
function toReportError(error, development) {
|
|
9
9
|
if (isQueueError(error)) return {
|
|
10
10
|
code: error.code,
|
|
11
11
|
docs: error.docs,
|
|
@@ -20,6 +20,11 @@ function toReportError(error) {
|
|
|
20
20
|
message: shape.message,
|
|
21
21
|
name: "ViteHubError"
|
|
22
22
|
};
|
|
23
|
+
if (development && error instanceof Error) return {
|
|
24
|
+
message: error.message,
|
|
25
|
+
name: error.name,
|
|
26
|
+
...error.stack ? { stack: error.stack } : {}
|
|
27
|
+
};
|
|
23
28
|
return {
|
|
24
29
|
message: "[vitehub] Queue Delivery failed.",
|
|
25
30
|
name: "Error"
|
|
@@ -33,7 +38,7 @@ function createQueueDeliveryErrorReport(error, context) {
|
|
|
33
38
|
provider: context.provider,
|
|
34
39
|
...id ? { id } : {},
|
|
35
40
|
...queue ? { queue } : {},
|
|
36
|
-
error: toReportError(error),
|
|
41
|
+
error: toReportError(error, context.development === true),
|
|
37
42
|
retryable: !isNonRetryableQueueError(error)
|
|
38
43
|
};
|
|
39
44
|
}
|
|
@@ -53,4 +58,4 @@ function checkQueueHandlerResponse(value) {
|
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
60
|
//#endregion
|
|
56
|
-
export {
|
|
61
|
+
export { reportQueueDeliveryError as i, createQueueDeliveryErrorReport as n, isNonRetryableQueueError as r, checkQueueHandlerResponse as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,53 +1,41 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import { i as createQueueCloudflareWorker } from "./cloudflare-vite-CjdP5yBN.js";
|
|
1
|
+
import { A as QueueJobStore, B as VercelQueueCallbackOptions, C as QueueDefinitionRegistry, D as QueueErrorCode, E as QueueEnqueueOptions, F as QueueRegistry, G as VercelQueueSendBatchMessage, H as VercelQueueErrorCode, I as QueueSendResult, K as VercelQueueSendBatchOptions, L as ResolvedLocalQueueOptions, M as QueueName, N as QueueOptions, O as QueueHandler, P as QueuePayload, R as ResolvedQueueOptions, S as QueueDefinitionOptions, T as QueueDriverOptions, U as VercelQueueRetryDirective, V as VercelQueueClient, W as VercelQueueRetryHandler, _ as PostgresQueueClient, a as CloudflareQueueMessageBatch, b as QueueClient, c as LocalQueueClient, g as NodeQueueDriver, i as CloudflareQueueMessage, j as QueueModuleDriverOptions, k as QueueJob, l as LocalQueueDriverOptions, m as LocalQueueSendBatchMessage, n as CloudflareQueueClient, o as CloudflareQueueSendBatchItem, p as LocalQueueRules, q as VercelQueueSendResult, r as CloudflareQueueErrorCode, s as DiscoveredQueueDefinition, t as CloudflareQueueBatchHandlerOptions, u as LocalQueueErrorCode, v as PostgresQueueDriverOptions, w as QueueDriver, x as QueueDefinition, y as PostgresQueueErrorCode, z as VercelQueueBatchSendResult } from "./types-CiuSIPR0.js";
|
|
3
2
|
import { Result } from "@vite-hub/runtime";
|
|
4
|
-
//#region src/config.d.ts
|
|
5
|
-
interface QueueResolutionInput {
|
|
6
|
-
hosting?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function normalizeQueueOptions(options: QueueModuleOptions | undefined, input?: QueueResolutionInput): ResolvedQueueOptions | undefined;
|
|
9
|
-
//#endregion
|
|
10
3
|
//#region src/definition.d.ts
|
|
11
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Defines a Queue from one object: `defineQueue({ handler, concurrency })`. The handler receives one object,
|
|
6
|
+
* `{ payload, id, attempts, metadata }`. The payload type of `handler` types `sendQueue()` for this Queue.
|
|
7
|
+
*/
|
|
8
|
+
export declare function defineQueue<TPayload = unknown, TResult = unknown>(definition: QueueDefinition<TPayload, TResult>): QueueDefinition<TPayload, TResult>;
|
|
12
9
|
//#endregion
|
|
13
10
|
//#region src/enqueue.d.ts
|
|
14
11
|
export declare function createQueueMessageId(prefix?: string): string;
|
|
15
12
|
//#endregion
|
|
16
|
-
//#region src/providers/cloudflare.d.ts
|
|
17
|
-
export declare function createCloudflareQueueBatchHandler<TPayload = unknown>(options: CloudflareQueueBatchHandlerOptions<TPayload>): (batch: CloudflareQueueMessageBatch<TPayload>) => Promise<void>;
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/integrations/cloudflare.d.ts
|
|
20
|
-
export declare function getCloudflareQueueBindingName(name: string): string;
|
|
21
|
-
export declare function getCloudflareQueueDefinitionName(name: string, namePrefix?: string): string;
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/internal/cloudflare-resource-name.d.ts
|
|
24
|
-
export declare function getCloudflareQueueName(name: string, namePrefix?: string): string;
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/integrations/vercel.d.ts
|
|
27
|
-
export declare function getVercelQueueTopicName(name: string): string;
|
|
28
|
-
//#endregion
|
|
29
13
|
//#region src/runtime/client.d.ts
|
|
30
|
-
declare function
|
|
31
|
-
declare function
|
|
14
|
+
declare function useDynamicQueue(name: string): Promise<QueueClient>;
|
|
15
|
+
declare function sendDynamicQueue(name: string, payload: unknown, options?: QueueEnqueueOptions): Promise<Result<QueueSendResult, QueueErrorCode>>;
|
|
32
16
|
declare function deferDynamicQueue(name: string, payload: unknown, options?: QueueEnqueueOptions): void;
|
|
33
17
|
/** Dispatch externally supplied names and payloads after application validation. */
|
|
34
18
|
export declare const dynamicQueue: {
|
|
35
19
|
defer: typeof deferDynamicQueue;
|
|
36
|
-
|
|
37
|
-
|
|
20
|
+
send: typeof sendDynamicQueue;
|
|
21
|
+
use: typeof useDynamicQueue;
|
|
38
22
|
};
|
|
39
23
|
/**
|
|
40
|
-
* Returns the QueueClient of a discovered Queue Definition. Config errors, for example an unknown name, throw.
|
|
24
|
+
* Returns the QueueClient of a discovered Queue Definition, for `sendBatch()` and provider methods. Config errors, for example an unknown name, throw.
|
|
41
25
|
*/
|
|
42
|
-
export declare function
|
|
26
|
+
export declare function useQueue<TName extends QueueName>(name: TName): Promise<QueueClient<QueueDriver, QueuePayload<TName>>>;
|
|
43
27
|
/**
|
|
44
|
-
*
|
|
28
|
+
* Sends one job to the Queue and returns `[error, result]`. `error.code` is a `QueueErrorCode`.
|
|
45
29
|
* Config errors, for example an unknown Queue name, throw.
|
|
46
30
|
*/
|
|
47
|
-
export declare function
|
|
31
|
+
export declare function sendQueue<TName extends QueueName>(name: TName, payload: NoInfer<QueuePayload<TName>>, options?: QueueEnqueueOptions): Promise<Result<QueueSendResult, QueueErrorCode>>;
|
|
32
|
+
/**
|
|
33
|
+
* Sends one job after the response, through `waitUntil`. It returns nothing: a failure goes to the log and to the
|
|
34
|
+
* `onDispatchError` option of the Queue Definition. Call `sendQueue()` when the caller needs the message ID.
|
|
35
|
+
*/
|
|
48
36
|
export declare function deferQueue<TName extends QueueName>(name: TName, payload: NoInfer<QueuePayload<TName>>, options?: QueueEnqueueOptions): void;
|
|
49
37
|
//#endregion
|
|
50
38
|
//#region src/runtime/create-client.d.ts
|
|
51
|
-
export declare function createQueueClient(options:
|
|
39
|
+
export declare function createQueueClient(options: QueueDriverOptions): Promise<QueueClient>;
|
|
52
40
|
//#endregion
|
|
53
|
-
export {
|
|
41
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
-
import {
|
|
4
|
-
import { n as
|
|
5
|
-
import { n as createCloudflareQueueBatchHandler } from "./cloudflare-client-COzQ8fHk.js";
|
|
6
|
-
import { t as getCloudflareQueueName } from "./cloudflare-resource-name-CCuLDvSP.js";
|
|
7
|
-
import { t as getVercelQueueTopicName } from "./vercel-C_4vqxcl.js";
|
|
8
|
-
import { i as runQueue, n as dynamicQueue, r as getQueue, t as deferQueue } from "./client-CIc3jsj2.js";
|
|
9
|
-
import { t as createQueueCloudflareWorker } from "./cloudflare-vite-BCuJOXcT.js";
|
|
1
|
+
import { n as isRecord } from "./object-D8pRdprI.js";
|
|
2
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-mJXBjmQx.js";
|
|
3
|
+
import { u as createQueueMessageId } from "./duration-tujyhAKt.js";
|
|
4
|
+
import { i as useQueue, n as dynamicQueue, r as sendQueue, t as deferQueue } from "./client-B53_G4ky.js";
|
|
10
5
|
//#region src/definition.ts
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
const queueDefinitionKeys = /* @__PURE__ */ new Set([
|
|
7
|
+
"cache",
|
|
8
|
+
"callbackOptions",
|
|
9
|
+
"concurrency",
|
|
10
|
+
"handler",
|
|
11
|
+
"onDispatchError",
|
|
12
|
+
"onError"
|
|
13
|
+
]);
|
|
14
|
+
function defineQueue(definition, ...removed) {
|
|
15
|
+
if (typeof definition === "function" || removed.length) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: "`defineQueue(handler, options)` was removed." });
|
|
16
|
+
if (!isRecord(definition)) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: "`defineQueue()` expects one object with `handler`." });
|
|
17
|
+
const unknownKey = Object.keys(definition).find((key) => !queueDefinitionKeys.has(key));
|
|
18
|
+
if (unknownKey) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: `\`defineQueue()\` does not support the "${unknownKey}" option.` });
|
|
19
|
+
if (!Object.hasOwn(definition, "handler") || typeof definition.handler !== "function") throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: "`defineQueue()` needs a `handler` function." });
|
|
20
|
+
return definition;
|
|
17
21
|
}
|
|
18
22
|
//#endregion
|
|
19
23
|
//#region src/runtime/create-client.ts
|
|
20
24
|
async function createQueueClient(options) {
|
|
21
|
-
if (options.
|
|
25
|
+
if (options.driver === void 0 && Object.hasOwn(options, "provider")) {
|
|
26
|
+
const provider = options.provider;
|
|
27
|
+
throw queueErrorDiagnostics.QUEUE_RENAMED_PROVIDER_KEY({ value: JSON.stringify(provider) ?? String(provider) });
|
|
28
|
+
}
|
|
29
|
+
if (options.driver === "cloudflare") {
|
|
22
30
|
const { createCloudflareQueueRuntimeClient } = await import("./internal/runtime/cloudflare-client.js");
|
|
23
31
|
return await createCloudflareQueueRuntimeClient(options);
|
|
24
32
|
}
|
|
33
|
+
if (options.driver === "local") {
|
|
34
|
+
const { createLocalQueueRuntimeClient } = await import("./internal/runtime/local-client.js");
|
|
35
|
+
return await createLocalQueueRuntimeClient({
|
|
36
|
+
base: options.base,
|
|
37
|
+
cache: options.cache,
|
|
38
|
+
driver: options.driver,
|
|
39
|
+
queue: options.queue,
|
|
40
|
+
rules: options.rules
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (options.driver === "postgres") {
|
|
44
|
+
const { createPostgresQueueRuntimeClient } = await import("#vitehub/queue/node-client");
|
|
45
|
+
return await createPostgresQueueRuntimeClient(options);
|
|
46
|
+
}
|
|
25
47
|
const { createVercelQueueRuntimeClient } = await import("./internal/runtime/vercel-client.js");
|
|
26
48
|
return await createVercelQueueRuntimeClient(options);
|
|
27
49
|
}
|
|
28
50
|
//#endregion
|
|
29
|
-
export {
|
|
51
|
+
export { createQueueClient, createQueueMessageId, deferQueue, defineQueue, dynamicQueue, sendQueue, useQueue };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { T as QueueDriverOptions, b as QueueClient } from "../../types-CiuSIPR0.js";
|
|
2
2
|
//#region src/internal/runtime/cloudflare-client.d.ts
|
|
3
|
-
export declare function createCloudflareQueueRuntimeClient(options:
|
|
3
|
+
export declare function createCloudflareQueueRuntimeClient(options: QueueDriverOptions): Promise<QueueClient>;
|
|
4
4
|
//#endregion
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-
|
|
1
|
+
import { t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-CoISDpIx.js";
|
|
2
2
|
export { createCloudflareQueueRuntimeClient };
|
|
@@ -1,2 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { C as QueueDefinitionRegistry, R as ResolvedQueueOptions, a as CloudflareQueueMessageBatch } from "../../types-CiuSIPR0.js";
|
|
2
|
+
//#region ../internal/src/runtime/cloudflare-env-lookup.d.ts
|
|
3
|
+
type CloudflareWorkerEnv = Record<string, unknown>;
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region ../internal/src/runtime/cloudflare-env.d.ts
|
|
6
|
+
interface CloudflareWorkerExecutionContext {
|
|
7
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region ../internal/src/runtime/app.d.ts
|
|
11
|
+
type AppHandler = (request: Request, context?: Record<string, unknown>) => Response | Promise<Response>;
|
|
12
|
+
type VitehubApp = AppHandler | {
|
|
13
|
+
fetch?: AppHandler;
|
|
14
|
+
request?: (request: Request, options?: RequestInit, context?: Record<string, unknown>) => Response | Promise<Response>;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/internal/runtime/cloudflare-vite.d.ts
|
|
18
|
+
export type CloudflareWorkerApp = VitehubApp;
|
|
19
|
+
export interface QueueCloudflareWorkerOptions {
|
|
20
|
+
app?: CloudflareWorkerApp;
|
|
21
|
+
definitions?: Record<string, string>;
|
|
22
|
+
queue?: false | ResolvedQueueOptions;
|
|
23
|
+
registry?: QueueDefinitionRegistry;
|
|
24
|
+
}
|
|
25
|
+
export interface QueueCloudflareWorker {
|
|
26
|
+
fetch: (request: Request, env: CloudflareWorkerEnv, context: CloudflareWorkerExecutionContext) => Promise<Response>;
|
|
27
|
+
queue: (batch: CloudflareQueueMessageBatch, env: CloudflareWorkerEnv, context: CloudflareWorkerExecutionContext) => Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export declare function createQueueCloudflareWorker(options?: QueueCloudflareWorkerOptions): QueueCloudflareWorker;
|
|
30
|
+
//#endregion
|
|
@@ -1,2 +1,112 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as queueErrorDiagnostics } from "../../error-diagnostics-mJXBjmQx.js";
|
|
2
|
+
import { _ as runWithActiveCloudflareEnv, c as loadQueueDefinition, d as setQueueRuntimeConfig, h as createCloudflareRuntimeEvent, m as setQueueRuntimeRegistry, u as runWithQueueRuntimeEvent } from "../../state-DLqTqF6V.js";
|
|
3
|
+
import { t as internalErrorDiagnostics } from "../../error-diagnostics-CQ4BUqRe.js";
|
|
4
|
+
import { n as normalizeQueueOptions } from "../../config-B2eaXaT5.js";
|
|
5
|
+
import { n as getCloudflareQueueDefinitionName } from "../../cloudflare-GosJefIK.js";
|
|
6
|
+
import { t as getCloudflareQueueName } from "../../cloudflare-resource-name-BIfBglC2.js";
|
|
7
|
+
import { n as createCloudflareQueueBatchHandler, t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-CoISDpIx.js";
|
|
8
|
+
import { runInRunScopes } from "@vite-hub/runtime/internal/run-scope";
|
|
9
|
+
//#region ../internal/src/runtime/app.ts
|
|
10
|
+
function resolveAppFetch(label, app) {
|
|
11
|
+
if (!app) return;
|
|
12
|
+
if (typeof app === "function") return app;
|
|
13
|
+
if (typeof app.request === "function") return (request, context) => app.request(request, void 0, context);
|
|
14
|
+
if (typeof app.fetch === "function") return app.fetch.bind(app);
|
|
15
|
+
throw internalErrorDiagnostics.INTERNAL_R0011({ message: `Invalid ${label} app. Expected an h3 app or a fetch-compatible handler.` });
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region ../internal/src/runtime/cloudflare-hosted.ts
|
|
19
|
+
function createWebRequestHandler(appHandler) {
|
|
20
|
+
return async (request, context) => await Promise.resolve(appHandler ? appHandler(request, context) : new Response(JSON.stringify({
|
|
21
|
+
status: 404,
|
|
22
|
+
message: `Cannot find any route matching [${request.method}] ${request.url}`
|
|
23
|
+
}), {
|
|
24
|
+
headers: { "content-type": "application/json;charset=UTF-8" },
|
|
25
|
+
status: 404,
|
|
26
|
+
statusText: "Not Found"
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
function createCloudflareHostedWorker(adapter) {
|
|
30
|
+
const requestHandler = createWebRequestHandler(resolveAppFetch(adapter.label, adapter.app));
|
|
31
|
+
return { async fetch(request, env, context) {
|
|
32
|
+
const handle = async (handlerContext) => await Promise.resolve(requestHandler(request, handlerContext));
|
|
33
|
+
if (adapter.onRequest) return await adapter.onRequest({
|
|
34
|
+
env,
|
|
35
|
+
executionContext: context,
|
|
36
|
+
handle
|
|
37
|
+
});
|
|
38
|
+
return await handle();
|
|
39
|
+
} };
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/runtime/cloudflare-shared.ts
|
|
43
|
+
function createQueueJob(message, batch) {
|
|
44
|
+
return {
|
|
45
|
+
attempts: typeof message.attempts === "number" ? message.attempts : 1,
|
|
46
|
+
id: message.id,
|
|
47
|
+
metadata: {
|
|
48
|
+
batch,
|
|
49
|
+
message
|
|
50
|
+
},
|
|
51
|
+
payload: message.body
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/internal/runtime/cloudflare-vite.ts
|
|
56
|
+
function createRegistryDefinitionNames(registry, namePrefix) {
|
|
57
|
+
if (!registry) return void 0;
|
|
58
|
+
const definitions = {};
|
|
59
|
+
for (const name of Object.keys(registry)) {
|
|
60
|
+
const physicalName = getCloudflareQueueName(name, namePrefix);
|
|
61
|
+
if (definitions[physicalName]) throw queueErrorDiagnostics.QUEUE_NAME_COLLISION({
|
|
62
|
+
first: definitions[physicalName],
|
|
63
|
+
resolved: physicalName,
|
|
64
|
+
second: name
|
|
65
|
+
});
|
|
66
|
+
definitions[physicalName] = name;
|
|
67
|
+
}
|
|
68
|
+
return definitions;
|
|
69
|
+
}
|
|
70
|
+
function createQueueCloudflareWorker(options = {}) {
|
|
71
|
+
const queueConfig = options.queue === false ? false : normalizeQueueOptions(options.queue, { hosting: "cloudflare" });
|
|
72
|
+
const registry = options.registry;
|
|
73
|
+
const definitions = options.definitions;
|
|
74
|
+
const registryDefinitions = !definitions && queueConfig !== false && queueConfig.driver === "cloudflare" ? createRegistryDefinitionNames(registry, queueConfig.namePrefix ?? "") : void 0;
|
|
75
|
+
const applyRuntimeState = () => {
|
|
76
|
+
setQueueRuntimeConfig(queueConfig, createCloudflareQueueRuntimeClient);
|
|
77
|
+
setQueueRuntimeRegistry(registry);
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
...createCloudflareHostedWorker({
|
|
81
|
+
app: options.app,
|
|
82
|
+
label: "queue",
|
|
83
|
+
async onRequest({ env, executionContext, handle }) {
|
|
84
|
+
applyRuntimeState();
|
|
85
|
+
const runtimeEvent = createCloudflareRuntimeEvent(env, executionContext);
|
|
86
|
+
return await runWithActiveCloudflareEnv(env, () => runWithQueueRuntimeEvent(runtimeEvent, () => handle(runtimeEvent.context)));
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
async queue(batch, env, context) {
|
|
90
|
+
applyRuntimeState();
|
|
91
|
+
if (queueConfig === false || queueConfig?.driver !== "cloudflare") return;
|
|
92
|
+
const runtimeEvent = createCloudflareRuntimeEvent(env, context);
|
|
93
|
+
await runWithActiveCloudflareEnv(env, async () => {
|
|
94
|
+
const definitionName = definitions ? Object.hasOwn(definitions, batch.queue) ? definitions[batch.queue] : void 0 : registryDefinitions?.[batch.queue] ?? (/-[0-9a-f]{32}$/.test(batch.queue) && !/(?:^|-)queue--(?:[0-9a-f]{2})+$/i.test(batch.queue) || queueConfig.namePrefix && !batch.queue.startsWith(queueConfig.namePrefix) ? void 0 : getCloudflareQueueDefinitionName(batch.queue, queueConfig.namePrefix));
|
|
95
|
+
if (!definitionName) throw queueErrorDiagnostics.QUEUE_DEFINITION_NOT_FOUND({ queue: batch.queue });
|
|
96
|
+
const definition = await loadQueueDefinition(definitionName);
|
|
97
|
+
if (!definition) throw queueErrorDiagnostics.QUEUE_DEFINITION_NOT_FOUND({ queue: definitionName });
|
|
98
|
+
await createCloudflareQueueBatchHandler({
|
|
99
|
+
concurrency: definition.concurrency,
|
|
100
|
+
onError: definition.onError,
|
|
101
|
+
onMessage: async (message, currentBatch) => {
|
|
102
|
+
await runWithQueueRuntimeEvent(runtimeEvent, async () => {
|
|
103
|
+
await runInRunScopes(() => definition.handler(createQueueJob(message, currentBatch)));
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
})(batch);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
2
112
|
export { createQueueCloudflareWorker };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { b as QueueClient, h as LocalQueueStatus } from "../../types-CiuSIPR0.js";
|
|
2
|
+
import { t as LocalQueueEngine } from "../../local-CUaWoRUx.js";
|
|
3
|
+
import { n as QueueRuntimeOptions, t as QueueRuntimeDriverOptions } from "../../types-Dsbb_Pvp.js";
|
|
4
|
+
//#region src/internal/runtime/local-client.d.ts
|
|
5
|
+
export declare function createLocalQueueRuntimeClient(options: QueueRuntimeDriverOptions): Promise<QueueClient>;
|
|
6
|
+
/**
|
|
7
|
+
* Starts delivery of the stored jobs when the server starts, so jobs from before a restart run without a new send.
|
|
8
|
+
* Logs once where the jobs are and what survives.
|
|
9
|
+
*/
|
|
10
|
+
export declare function startLocalQueue(config: false | QueueRuntimeOptions): void;
|
|
11
|
+
/** The engine of the stored jobs, for `vitehub queue list`, `vitehub queue jobs`, and the Console. */
|
|
12
|
+
export declare function useLocalQueueEngine(config: QueueRuntimeOptions): LocalQueueEngine | undefined;
|
|
13
|
+
/** Status of the stored jobs, for `vitehub queue list` and the Console. */
|
|
14
|
+
export declare function getLocalQueueStatus(config: QueueRuntimeOptions): Promise<LocalQueueStatus | undefined>;
|
|
15
|
+
/** Stops the timers of every local engine. The stored jobs stay. */
|
|
16
|
+
export declare function closeLocalQueues(): void;
|
|
17
|
+
//#endregion
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { t as queueErrorDiagnostics } from "../../error-diagnostics-mJXBjmQx.js";
|
|
2
|
+
import { c as loadQueueDefinition, l as missingQueueDefinitionError } from "../../state-DLqTqF6V.js";
|
|
3
|
+
import { t as defaultLocalQueueBase } from "../../config-B2eaXaT5.js";
|
|
4
|
+
import { i as localQueueDeliveryRules, n as createLocalQueueEngine, t as createLocalQueueClient } from "../../local-Di0FrVUw.js";
|
|
5
|
+
import { resolve } from "pathe";
|
|
6
|
+
//#region src/internal/runtime/local-client.ts
|
|
7
|
+
const engines = /* @__PURE__ */ new Map();
|
|
8
|
+
function getLocalQueueEngine({ base = defaultLocalQueueBase, development, rules = "local" }) {
|
|
9
|
+
const directory = resolve(base);
|
|
10
|
+
const cached = engines.get(directory);
|
|
11
|
+
const discloseErrors = development === true;
|
|
12
|
+
if (cached) {
|
|
13
|
+
if (cached.development !== discloseErrors) throw queueErrorDiagnostics.QUEUE_LOCAL_MODE_MISMATCH();
|
|
14
|
+
return cached.engine;
|
|
15
|
+
}
|
|
16
|
+
const engine = createLocalQueueEngine({
|
|
17
|
+
base: directory,
|
|
18
|
+
development: discloseErrors,
|
|
19
|
+
load: loadQueueDefinition,
|
|
20
|
+
missing: missingQueueDefinitionError,
|
|
21
|
+
rules: localQueueDeliveryRules[rules]
|
|
22
|
+
});
|
|
23
|
+
engines.set(directory, {
|
|
24
|
+
development: discloseErrors,
|
|
25
|
+
engine
|
|
26
|
+
});
|
|
27
|
+
return engine;
|
|
28
|
+
}
|
|
29
|
+
async function createLocalQueueRuntimeClient(options) {
|
|
30
|
+
if (options.driver !== "local") throw queueErrorDiagnostics.QUEUE_DRIVER_MISMATCH({
|
|
31
|
+
driver: options.driver,
|
|
32
|
+
expected: "local"
|
|
33
|
+
});
|
|
34
|
+
if (!options.queue) throw queueErrorDiagnostics.QUEUE_MISSING_QUEUE();
|
|
35
|
+
return createLocalQueueClient(getLocalQueueEngine(options), options.queue);
|
|
36
|
+
}
|
|
37
|
+
const providerNames = {
|
|
38
|
+
cloudflare: "Cloudflare",
|
|
39
|
+
local: "local",
|
|
40
|
+
postgres: "Postgres",
|
|
41
|
+
vercel: "Vercel"
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Starts delivery of the stored jobs when the server starts, so jobs from before a restart run without a new send.
|
|
45
|
+
* Logs once where the jobs are and what survives.
|
|
46
|
+
*/
|
|
47
|
+
function startLocalQueue(config) {
|
|
48
|
+
if (config === false || config.driver !== "local") return;
|
|
49
|
+
const engine = getLocalQueueEngine(config);
|
|
50
|
+
if (config.rules && config.rules !== "local") console.warn(`[vitehub:queue] The dev server runs Queue jobs in this process with the ${providerNames[config.rules]} delivery rules. It stores them in ${engine.base}. The build uses ${providerNames[config.rules]} Queues. Run \`vitehub queue jobs list\` to inspect the jobs.`);
|
|
51
|
+
else console.warn(`[vitehub:queue] Queue uses the local driver. This process stores jobs in ${engine.base} and runs them. The jobs survive a restart on this host, but not a move to another host or a new container. Run one server process per directory.`);
|
|
52
|
+
engine.start().catch((error) => {
|
|
53
|
+
console.error(`[vitehub:queue] The local driver cannot read the stored jobs in ${engine.base}.`, error);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** The engine of the stored jobs, for `vitehub queue list`, `vitehub queue jobs`, and the Console. */
|
|
57
|
+
function useLocalQueueEngine(config) {
|
|
58
|
+
if (config.driver !== "local") return;
|
|
59
|
+
return getLocalQueueEngine(config);
|
|
60
|
+
}
|
|
61
|
+
/** Status of the stored jobs, for `vitehub queue list` and the Console. */
|
|
62
|
+
async function getLocalQueueStatus(config) {
|
|
63
|
+
return await useLocalQueueEngine(config)?.status();
|
|
64
|
+
}
|
|
65
|
+
/** Stops the timers of every local engine. The stored jobs stay. */
|
|
66
|
+
function closeLocalQueues() {
|
|
67
|
+
for (const { engine } of engines.values()) engine.close();
|
|
68
|
+
engines.clear();
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { closeLocalQueues, createLocalQueueRuntimeClient, getLocalQueueStatus, startLocalQueue, useLocalQueueEngine };
|