@vite-hub/queue 0.6.1 → 0.8.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-mT8TUaag.js} +46 -15
- package/dist/{cloudflare-client-xWteD-su.js → cloudflare-client-DBgvWY0z.js} +14 -42
- 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-BZKArIBP.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-DKhsmxDV.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 +8 -6
- package/dist/internal/runtime/postgres-client.js +178 -40
- 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 +28 -57
- 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-5pcvR1RC.js} +148 -97
- package/dist/{local-B72WRWkS.d.ts → local-DUh8sGn-.d.ts} +1 -1
- package/dist/{operations-CoEXxfUW.js → operations-BSouq47k.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-COXFYL5z.js +61 -0
- package/dist/runtime/hosted.d.ts +1 -1
- package/dist/runtime/hosted.js +32 -20
- package/dist/{scan-module-BaqBao0J.js → scan-module-3HfnrGbT.js} +16 -1
- package/dist/source-files-DrAH1-c8.js +147 -0
- 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 +2 -155
- package/dist/vite.js +522 -138
- package/package.json +4 -3
|
@@ -1,3 +1,171 @@
|
|
|
1
|
+
import "nostics";
|
|
2
|
+
interface HostCliRunResult {
|
|
3
|
+
exitCode: number | null;
|
|
4
|
+
stdout: string;
|
|
5
|
+
stderr?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Runs a host CLI with an argument array and no shell, and returns its stdout. */
|
|
8
|
+
type HostCliRun = (command: string, args: readonly string[], options: {
|
|
9
|
+
cwd?: string;
|
|
10
|
+
env: NodeJS.ProcessEnv;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}) => Promise<HostCliRunResult>;
|
|
13
|
+
type ProvisionProvider = "cloudflare" | "vercel";
|
|
14
|
+
interface ProvisionLogger {
|
|
15
|
+
log: (message: string) => void;
|
|
16
|
+
warn: (message: string) => void;
|
|
17
|
+
}
|
|
18
|
+
interface ProvisionContext {
|
|
19
|
+
env: Record<string, string | undefined>;
|
|
20
|
+
fetch: typeof globalThis.fetch;
|
|
21
|
+
logger: ProvisionLogger;
|
|
22
|
+
markPlanUnchecked?: () => void;
|
|
23
|
+
}
|
|
24
|
+
interface ProvisionState {
|
|
25
|
+
cloudflare?: Record<string, Record<string, string>>;
|
|
26
|
+
vercel?: Record<string, Record<string, string>>;
|
|
27
|
+
}
|
|
28
|
+
interface ProvisionResult {
|
|
29
|
+
ids?: ProvisionState;
|
|
30
|
+
}
|
|
31
|
+
interface ProvisionAction {
|
|
32
|
+
kind: string;
|
|
33
|
+
name: string;
|
|
34
|
+
exists: boolean;
|
|
35
|
+
pending?: boolean;
|
|
36
|
+
/** Describes the change that `apply()` makes to an existing resource, for example `read replication: disabled -> auto`. */
|
|
37
|
+
update?: string;
|
|
38
|
+
apply: () => Promise<ProvisionResult>;
|
|
39
|
+
}
|
|
40
|
+
/** One Provision State category that a step records, with the keys that current Definitions use. */
|
|
41
|
+
interface ProvisionStateCategory {
|
|
42
|
+
category: string;
|
|
43
|
+
declared: readonly string[];
|
|
44
|
+
/** Provider resource identity for shared-resource checks. Return undefined when the recorded id lacks enough information. Defaults to the recorded id. */
|
|
45
|
+
resourceIdentity?: (entry: {
|
|
46
|
+
id: string;
|
|
47
|
+
key: string;
|
|
48
|
+
}) => string | undefined;
|
|
49
|
+
/** Identity expected by current config for a declared key. Omit when it cannot be established without provider access. */
|
|
50
|
+
declaredResourceIdentity?: (key: string) => string | undefined;
|
|
51
|
+
/** Tells a developer how to delete the resource of a recorded entry that no Definition declares. ViteHub never runs it. */
|
|
52
|
+
deleteHint: (entry: {
|
|
53
|
+
id: string;
|
|
54
|
+
key: string;
|
|
55
|
+
}) => string;
|
|
56
|
+
}
|
|
57
|
+
interface ProvisionStep {
|
|
58
|
+
id: string;
|
|
59
|
+
provider: ProvisionProvider;
|
|
60
|
+
plan: (context: ProvisionContext) => Promise<ProvisionAction[]>;
|
|
61
|
+
hasResources?: (context: Pick<ProvisionContext, "env">) => boolean;
|
|
62
|
+
/** Describes the Provision State this step records. Runs without network access, also without credentials. */
|
|
63
|
+
recordedState?: (context: Pick<ProvisionContext, "env">) => ProvisionStateCategory[];
|
|
64
|
+
}
|
|
65
|
+
interface ViteHubCliStreams {
|
|
66
|
+
stderr: {
|
|
67
|
+
write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
|
|
68
|
+
};
|
|
69
|
+
stdout: {
|
|
70
|
+
write: (chunk: string | Uint8Array) => unknown;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
interface ViteHubCliSpawnResult {
|
|
74
|
+
exitCode: number | null;
|
|
75
|
+
signal?: NodeJS.Signals | null;
|
|
76
|
+
/** The output of the child when `stdout` is `pipe`. */
|
|
77
|
+
stdout?: string;
|
|
78
|
+
/** The error output of the child when `stderr` is `pipe`. */
|
|
79
|
+
stderr?: string;
|
|
80
|
+
}
|
|
81
|
+
interface ViteHubCliSpawnOptions {
|
|
82
|
+
cwd?: string;
|
|
83
|
+
env?: NodeJS.ProcessEnv;
|
|
84
|
+
onOutput?: (text: string, stream: "stdout" | "stderr") => void;
|
|
85
|
+
stderr?: "inherit" | "pipe";
|
|
86
|
+
/** `ignore` gives the child no terminal input, so a tool that asks questions on a terminal does not ask. */
|
|
87
|
+
stdin?: "ignore" | "inherit";
|
|
88
|
+
/** `stderr` sends the child's stdout to the parent's stderr, so the parent's stdout keeps only its own output. */
|
|
89
|
+
stdout?: "inherit" | "pipe" | "stderr";
|
|
90
|
+
}
|
|
91
|
+
type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
|
|
92
|
+
/** Where a call to an app goes through the Console: the operation endpoint of the app's Console project, and the token of `vitehub login`. */
|
|
93
|
+
interface ViteHubCliConsoleRoute {
|
|
94
|
+
authorization: string;
|
|
95
|
+
target: string;
|
|
96
|
+
}
|
|
97
|
+
interface ViteHubCliContext extends ViteHubCliStreams {
|
|
98
|
+
/**
|
|
99
|
+
* Finds the app at `url` in the Console of `vitehub login` and returns the route that lets the Console sign the call.
|
|
100
|
+
* Returns nothing when the command must call the app directly, such as when a `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` is set.
|
|
101
|
+
*/
|
|
102
|
+
consoleRoute?: (url: string, signal: AbortSignal) => Promise<ViteHubCliConsoleRoute | undefined>;
|
|
103
|
+
cwd: string;
|
|
104
|
+
env: NodeJS.ProcessEnv;
|
|
105
|
+
/** Replaces `fetch` for commands that call a running app, so tests need no server. */
|
|
106
|
+
fetch?: typeof fetch;
|
|
107
|
+
/**
|
|
108
|
+
* Loads the project config for a build on `host` and returns the Provision Steps of its plugins, with the config root
|
|
109
|
+
* that holds `.vitehub/provision.json`. Setup commands, such as `vitehub deploy`, call it only when they need the
|
|
110
|
+
* steps, so they still run on a config that throws.
|
|
111
|
+
*/
|
|
112
|
+
loadProvision?: (host: ProvisionProvider) => Promise<ViteHubCliProvision>;
|
|
113
|
+
/** The deployed app's public origin from `vitehub({ publicUrl })`, when it is one string. */
|
|
114
|
+
publicUrl?: string;
|
|
115
|
+
rootDir: string;
|
|
116
|
+
/** Replaces the host CLI runner, such as for `wrangler auth token`, so tests need no real host CLI. */
|
|
117
|
+
runHostCli?: HostCliRun;
|
|
118
|
+
spawn: ViteHubCliSpawn;
|
|
119
|
+
}
|
|
120
|
+
interface ViteHubCliProvision {
|
|
121
|
+
env?: NodeJS.ProcessEnv;
|
|
122
|
+
rootDir: string;
|
|
123
|
+
steps: readonly ProvisionStep[];
|
|
124
|
+
}
|
|
125
|
+
interface ViteHubCliFeature {
|
|
126
|
+
description?: string;
|
|
127
|
+
name: string;
|
|
128
|
+
run: (args: string[], context: ViteHubCliContext) => Promise<number | void> | number | void;
|
|
129
|
+
usage?: string;
|
|
130
|
+
}
|
|
131
|
+
interface ViteHubCliCommandNamespace {
|
|
132
|
+
/** The feature that `vitehub <name>` runs when the next argument names no other feature. It gets every argument after `<name>`. */
|
|
133
|
+
defaultFeature?: string;
|
|
134
|
+
description?: string;
|
|
135
|
+
features: ViteHubCliFeature[];
|
|
136
|
+
name: string;
|
|
137
|
+
}
|
|
138
|
+
/** The flags of `vitehub seed` that every seed gets. */
|
|
139
|
+
interface ViteHubCliSeedOptions {
|
|
140
|
+
/** `--database <name>`: seed only this Database. Only the Database seed runs. */
|
|
141
|
+
database?: string;
|
|
142
|
+
/** The process environment with the env files of `--stage`. */
|
|
143
|
+
env: NodeJS.ProcessEnv;
|
|
144
|
+
/** `--remote`: write the deployed stores. Without it, a seed writes only local data. */
|
|
145
|
+
remote: boolean;
|
|
146
|
+
/** `--timeout <ms>` of each call to the app. */
|
|
147
|
+
timeout?: number;
|
|
148
|
+
/** The deployed app with `--remote`: `--url`, or `vitehub({ publicUrl })`. */
|
|
149
|
+
url?: string;
|
|
150
|
+
}
|
|
151
|
+
/** The seed files of one primitive, which `vitehub seed` writes. */
|
|
152
|
+
interface ViteHubCliSeed {
|
|
153
|
+
/** Where the seed files are, such as `server/seed/kv/`. `vitehub seed` names it when it finds no seed files. */
|
|
154
|
+
files: string;
|
|
155
|
+
/** The primitive, such as `database` or `kv`. `vitehub seed <name>` runs only this seed. */
|
|
156
|
+
name: string;
|
|
157
|
+
/** Writes the seed files and returns the exit code, or `undefined` when the project has no seed files for this primitive. */
|
|
158
|
+
run: (options: ViteHubCliSeedOptions, context: ViteHubCliContext) => Promise<number | undefined>;
|
|
159
|
+
}
|
|
160
|
+
interface ViteHubCliContributor {
|
|
161
|
+
namespaces: ViteHubCliCommandNamespace[];
|
|
162
|
+
provision?: ProvisionStep[];
|
|
163
|
+
/** The seed files that `vitehub seed` writes. */
|
|
164
|
+
seeds?: ViteHubCliSeed[];
|
|
165
|
+
/** The deployed app's public origin. Commands receive it as `context.publicUrl`. */
|
|
166
|
+
publicUrl?: string;
|
|
167
|
+
}
|
|
168
|
+
type StdoutWriteCallback = (error?: Error | null) => void;
|
|
1
169
|
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
2
170
|
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
3
171
|
/** The Standard properties. */
|
|
@@ -238,4 +406,4 @@ interface OperationContributionEntry {
|
|
|
238
406
|
/** `false`: the app already has these operations at runtime. Only tools such as the CLI and `vitehub inspect` read the entry. */
|
|
239
407
|
runtime?: false;
|
|
240
408
|
}
|
|
241
|
-
export { OperationContributionEntry as n, AnyOperation as t };
|
|
409
|
+
export { OperationContributionEntry as n, ViteHubCliContributor as r, AnyOperation as t };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as AnyOperation } from "./
|
|
2
|
-
import "./local-
|
|
3
|
-
import {
|
|
1
|
+
import { t as AnyOperation } from "./operations-DSslh_vK.js";
|
|
2
|
+
import "./local-DUh8sGn-.js";
|
|
3
|
+
import { T as QueueDriver, d as LocalQueueJob, f as LocalQueueJobDetail, h as LocalQueueStatus, j as QueueJobStore, p as LocalQueueRules, z as QueueRetryDeadResult } from "./types-rZHAtkK0.js";
|
|
4
4
|
interface QueueListResult {
|
|
5
5
|
/** `undefined` when the runtime has not installed a Queue configuration. */
|
|
6
6
|
provider?: QueueDriver;
|
|
@@ -23,6 +23,8 @@ interface QueueListResult {
|
|
|
23
23
|
pending?: number;
|
|
24
24
|
running?: number;
|
|
25
25
|
}>;
|
|
26
|
+
/** The postgres provider only: whether this server process runs jobs. `QUEUE_WORKERS=false` sets it to `false`. */
|
|
27
|
+
workers?: boolean;
|
|
26
28
|
}
|
|
27
29
|
interface QueueJobsListInput {
|
|
28
30
|
queue?: string;
|
|
@@ -57,10 +59,17 @@ interface QueueSendOperationInput {
|
|
|
57
59
|
payload: unknown;
|
|
58
60
|
queue: string;
|
|
59
61
|
}
|
|
62
|
+
interface QueueJobsRetryInput {
|
|
63
|
+
/** The message ID of one job. */
|
|
64
|
+
id?: string;
|
|
65
|
+
/** With `state: "dead"` and no `id`: every dead job of this Queue Definition. */
|
|
66
|
+
queue?: string;
|
|
67
|
+
state?: "dead";
|
|
68
|
+
}
|
|
60
69
|
/**
|
|
61
70
|
* The `queue.*` operations: list and send, and the stored jobs of the local and postgres providers. `vite dev` runs
|
|
62
71
|
* every job with the local provider. Cloudflare and Vercel do not let a producer read their queue, so the job
|
|
63
72
|
* operations fail there.
|
|
64
73
|
*/
|
|
65
74
|
export declare const queueOperations: readonly AnyOperation[];
|
|
66
|
-
export type { LocalQueueJob, LocalQueueJobDetail, QueueJobsClearInput, QueueJobsListInput, QueueJobsListResult, QueueListResult, QueueSendOperationInput, QueueSendOperationResult };
|
|
75
|
+
export type { LocalQueueJob, LocalQueueJobDetail, QueueJobsClearInput, QueueJobsListInput, QueueJobsListResult, QueueJobsRetryInput, QueueListResult, QueueRetryDeadResult, QueueSendOperationInput, QueueSendOperationResult };
|
package/dist/operations.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as isRecordOrFunction } from "./object-DRSmpe04.js";
|
|
2
|
-
import { t as internalErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { t as internalErrorDiagnostics } from "./error-diagnostics-CsiNo_oI.js";
|
|
3
3
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
4
4
|
// ../internal/src/standard-schema.ts
|
|
5
5
|
function readOwn(value, key) {
|
|
@@ -214,6 +214,21 @@ function _addIssue(context, label, dataset, config$1, other) {
|
|
|
214
214
|
else dataset.issues = [issue];
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
217
|
+
* Compares two values using the SameValueZero algorithm, which treats `NaN`
|
|
218
|
+
* as equal to itself unlike `===`.
|
|
219
|
+
*
|
|
220
|
+
* @param value1 The first value.
|
|
221
|
+
* @param value2 The second value.
|
|
222
|
+
*
|
|
223
|
+
* @returns Whether the values are equal.
|
|
224
|
+
*
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
228
|
+
function _isSameValueZero(value1, value2) {
|
|
229
|
+
return value1 === value2 || Number.isNaN(value1) && Number.isNaN(value2);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
217
232
|
* Joins multiple `expects` values with the given separator.
|
|
218
233
|
*
|
|
219
234
|
* @param values The `expects` values.
|
|
@@ -249,6 +264,22 @@ function _standardSchema(schema) {
|
|
|
249
264
|
};
|
|
250
265
|
return schema;
|
|
251
266
|
}
|
|
267
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
268
|
+
function check(requirement, message$1) {
|
|
269
|
+
return {
|
|
270
|
+
kind: "validation",
|
|
271
|
+
type: "check",
|
|
272
|
+
reference: check,
|
|
273
|
+
async: false,
|
|
274
|
+
expects: null,
|
|
275
|
+
requirement,
|
|
276
|
+
message: message$1,
|
|
277
|
+
"~run"(dataset, config$1) {
|
|
278
|
+
if (dataset.typed && !this.requirement(dataset.value)) _addIssue(this, "input", dataset, config$1);
|
|
279
|
+
return dataset;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}
|
|
252
283
|
/**
|
|
253
284
|
* Creates a description metadata action.
|
|
254
285
|
*
|
|
@@ -308,6 +339,23 @@ function getDefault(schema, dataset, config$1) {
|
|
|
308
339
|
return typeof schema.default === "function" ? schema.default(dataset, config$1) : schema.default;
|
|
309
340
|
}
|
|
310
341
|
/* @__NO_SIDE_EFFECTS__ */
|
|
342
|
+
function literal(literal_, message$1) {
|
|
343
|
+
return _standardSchema({
|
|
344
|
+
kind: "schema",
|
|
345
|
+
type: "literal",
|
|
346
|
+
reference: literal,
|
|
347
|
+
expects: /* @__PURE__ */ _stringify(literal_),
|
|
348
|
+
async: false,
|
|
349
|
+
literal: literal_,
|
|
350
|
+
message: message$1,
|
|
351
|
+
"~run"(dataset, config$1) {
|
|
352
|
+
if (/* @__PURE__ */ _isSameValueZero(dataset.value, this.literal)) dataset.typed = true;
|
|
353
|
+
else _addIssue(this, "type", dataset, config$1);
|
|
354
|
+
return dataset;
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
311
359
|
function optional(wrapped, default_) {
|
|
312
360
|
return _standardSchema({
|
|
313
361
|
kind: "schema",
|
|
@@ -477,7 +525,7 @@ function pipe(...pipe$1) {
|
|
|
477
525
|
});
|
|
478
526
|
}
|
|
479
527
|
// src/operations.ts
|
|
480
|
-
const runtime = () => import("./operations-
|
|
528
|
+
const runtime = () => import("./operations-BSouq47k.js");
|
|
481
529
|
function defineQueueOperation(definition) {
|
|
482
530
|
return defineOperation({
|
|
483
531
|
...definition,
|
|
@@ -553,6 +601,44 @@ function formatJob({ job }) {
|
|
|
553
601
|
""
|
|
554
602
|
].join("\n");
|
|
555
603
|
}
|
|
604
|
+
const jobsList = defineQueueOperation({
|
|
605
|
+
cli: {
|
|
606
|
+
command: "jobs list",
|
|
607
|
+
format: formatJobs,
|
|
608
|
+
namespace: "queue"
|
|
609
|
+
},
|
|
610
|
+
description: "List the stored Queue jobs, newest first: pending, running, and dead jobs, from the local or postgres provider. In `vite dev` every job runs in the dev server, so this lists them for any provider.",
|
|
611
|
+
input: /* @__PURE__ */ strictObject({
|
|
612
|
+
queue: /* @__PURE__ */ optional(queueName),
|
|
613
|
+
state: /* @__PURE__ */ optional(/* @__PURE__ */ picklist([
|
|
614
|
+
"dead",
|
|
615
|
+
"pending",
|
|
616
|
+
"running"
|
|
617
|
+
]))
|
|
618
|
+
}),
|
|
619
|
+
kind: "read",
|
|
620
|
+
name: "queue.jobs-list",
|
|
621
|
+
run: async (input) => (await runtime()).listQueueJobs(input)
|
|
622
|
+
});
|
|
623
|
+
const jobsShow = defineQueueOperation({
|
|
624
|
+
cli: {
|
|
625
|
+
command: "jobs get",
|
|
626
|
+
format: formatJob,
|
|
627
|
+
namespace: "queue",
|
|
628
|
+
positional: ["id"]
|
|
629
|
+
},
|
|
630
|
+
description: "Show one stored Queue job by message ID, with its payload, attempts, and last error.",
|
|
631
|
+
input: /* @__PURE__ */ strictObject({ id: jobId }),
|
|
632
|
+
kind: "read",
|
|
633
|
+
name: "queue.jobs-show",
|
|
634
|
+
run: async (input) => (await runtime()).showQueueJob(input.id)
|
|
635
|
+
});
|
|
636
|
+
function formatRetry(result) {
|
|
637
|
+
if ("job" in result) return `${JSON.stringify(result, null, 2)}\n`;
|
|
638
|
+
const retried = `Retried ${result.retried} dead job${result.retried === 1 ? "" : "s"}.\n`;
|
|
639
|
+
if (!result.skipped.length) return retried;
|
|
640
|
+
return `${retried}Skipped ${result.skipped.length} dead job${result.skipped.length === 1 ? "" : "s"} whose idempotency key a newer job holds:\n${result.skipped.join("\n")}\n`;
|
|
641
|
+
}
|
|
556
642
|
/**
|
|
557
643
|
* The `queue.*` operations: list and send, and the stored jobs of the local and postgres providers. `vite dev` runs
|
|
558
644
|
* every job with the local provider. Cloudflare and Vercel do not let a producer read their queue, so the job
|
|
@@ -561,50 +647,25 @@ function formatJob({ job }) {
|
|
|
561
647
|
const queueOperations = [
|
|
562
648
|
list,
|
|
563
649
|
send,
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
command: "jobs list",
|
|
567
|
-
format: formatJobs,
|
|
568
|
-
namespace: "queue"
|
|
569
|
-
},
|
|
570
|
-
description: "List the stored Queue jobs, newest first: pending, running, and dead jobs, from the local or postgres provider. In `vite dev` every job runs in the dev server, so this lists them for any provider.",
|
|
571
|
-
input: /* @__PURE__ */ strictObject({
|
|
572
|
-
queue: /* @__PURE__ */ optional(queueName),
|
|
573
|
-
state: /* @__PURE__ */ optional(/* @__PURE__ */ picklist([
|
|
574
|
-
"dead",
|
|
575
|
-
"pending",
|
|
576
|
-
"running"
|
|
577
|
-
]))
|
|
578
|
-
}),
|
|
579
|
-
kind: "read",
|
|
580
|
-
name: "queue.jobs-list",
|
|
581
|
-
run: async (input) => (await runtime()).listQueueJobs(input)
|
|
582
|
-
}),
|
|
583
|
-
defineQueueOperation({
|
|
584
|
-
cli: {
|
|
585
|
-
command: "jobs get",
|
|
586
|
-
format: formatJob,
|
|
587
|
-
namespace: "queue",
|
|
588
|
-
positional: ["id"]
|
|
589
|
-
},
|
|
590
|
-
description: "Show one stored Queue job by message ID, with its payload, attempts, and last error.",
|
|
591
|
-
input: /* @__PURE__ */ strictObject({ id: jobId }),
|
|
592
|
-
kind: "read",
|
|
593
|
-
name: "queue.jobs-show",
|
|
594
|
-
run: async (input) => (await runtime()).showQueueJob(input.id)
|
|
595
|
-
}),
|
|
650
|
+
jobsList,
|
|
651
|
+
jobsShow,
|
|
596
652
|
defineQueueOperation({
|
|
597
653
|
cli: {
|
|
598
654
|
command: "jobs retry",
|
|
655
|
+
format: formatRetry,
|
|
599
656
|
namespace: "queue",
|
|
600
657
|
positional: ["id"]
|
|
601
658
|
},
|
|
602
|
-
description: "Run a stored Queue job now. A dead job gets a new set of attempts. The call returns before the
|
|
603
|
-
input: /* @__PURE__ */
|
|
659
|
+
description: "Run a stored Queue job now, by message ID. A dead job gets a new set of attempts. With `queue` and `state: dead` instead of an ID, every dead job of that queue runs again, in batches of 500, and a dead job whose idempotency key a newer job holds is skipped. The call returns before the handlers end.",
|
|
660
|
+
input: /* @__PURE__ */ pipe(/* @__PURE__ */ strictObject({
|
|
661
|
+
id: /* @__PURE__ */ optional(jobId),
|
|
662
|
+
queue: /* @__PURE__ */ optional(queueName),
|
|
663
|
+
state: /* @__PURE__ */ optional(/* @__PURE__ */ pipe(/* @__PURE__ */ literal("dead"), /* @__PURE__ */ description("With `queue`: retry every dead job of that queue.")))
|
|
664
|
+
}), /* @__PURE__ */ check((input) => input.id === void 0 ? input.queue !== void 0 && input.state === "dead" : input.queue === void 0 && input.state === void 0, "Pass a job `id`, or `queue` with `state: \"dead\"`.")),
|
|
604
665
|
invoke: true,
|
|
605
666
|
kind: "write",
|
|
606
667
|
name: "queue.jobs-retry",
|
|
607
|
-
run: async (input) => (await runtime()).retryQueueJob(input.id)
|
|
668
|
+
run: async (input) => input.id === void 0 ? (await runtime()).retryDeadQueueJobs(input.queue) : (await runtime()).retryQueueJob(input.id)
|
|
608
669
|
}),
|
|
609
670
|
defineQueueOperation({
|
|
610
671
|
cli: {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { parseDuration } from "@vite-hub/runtime";
|
|
2
|
+
// src/internal/retries.ts
|
|
3
|
+
const defaultQueueRetries = {
|
|
4
|
+
backoff: "exponential",
|
|
5
|
+
delay: "10 seconds",
|
|
6
|
+
limit: 3
|
|
7
|
+
};
|
|
8
|
+
const cloudflareMaxRetryDelayMs = 432e5;
|
|
9
|
+
function queueRetryPolicy(retries) {
|
|
10
|
+
const backoff = retries?.backoff ?? defaultQueueRetries.backoff;
|
|
11
|
+
const first = parseDuration(retries?.delay ?? defaultQueueRetries.delay, "retries.delay");
|
|
12
|
+
return {
|
|
13
|
+
delayMs: (attempts) => Math.min(backoff === "exponential" ? first * 2 ** Math.max(0, attempts - 1) : first, cloudflareMaxRetryDelayMs),
|
|
14
|
+
limit: retries?.limit ?? defaultQueueRetries.limit
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Returns why `retries` is invalid, or `undefined`. */
|
|
18
|
+
function invalidQueueRetries(retries) {
|
|
19
|
+
if (typeof retries !== "object" || retries === null || Array.isArray(retries)) return "`retries` must be an object such as `{ limit: 5, delay: \"30s\" }`.";
|
|
20
|
+
const unknownKey = Object.keys(retries).find((key) => key !== "backoff" && key !== "delay" && key !== "limit");
|
|
21
|
+
if (unknownKey) return `\`retries\` does not support the "${unknownKey}" option.`;
|
|
22
|
+
const { backoff, delay, limit } = retries;
|
|
23
|
+
if (limit !== void 0 && !(Number.isInteger(limit) && limit >= 0 && limit <= 100)) return "`retries.limit` must be a whole number from 0 to 100.";
|
|
24
|
+
if (backoff !== void 0 && backoff !== "constant" && backoff !== "exponential") return "`retries.backoff` must be \"constant\" or \"exponential\".";
|
|
25
|
+
if (delay !== void 0) parseDuration(delay, "retries.delay");
|
|
26
|
+
}
|
|
27
|
+
export { queueRetryPolicy as n, invalidQueueRetries as t };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
2
|
+
import { t as checkQueueHandlerResponse } from "./handler-response-DKhsmxDV.js";
|
|
3
|
+
import { parseDuration } from "@vite-hub/runtime";
|
|
4
|
+
import { runInRunScopes } from "@vite-hub/runtime/internal/run-scope";
|
|
5
|
+
// src/internal/run-handler.ts
|
|
6
|
+
const defaultQueueTimeout = "15 minutes";
|
|
7
|
+
const maxTimerDelay = 2147483647;
|
|
8
|
+
/**
|
|
9
|
+
* Runs one attempt of a Queue handler inside the run scopes and checks its HTTP response there, so a failed status or a
|
|
10
|
+
* timeout drops the writes that the attempt staged, such as Workspace writes. When the Definition's `timeout` passes,
|
|
11
|
+
* `job.signal` aborts and the attempt fails with `QUEUE_JOB_TIMEOUT`, so the provider frees the slot and retries the
|
|
12
|
+
* job. A handler that ignores the signal keeps running in the background.
|
|
13
|
+
*/
|
|
14
|
+
async function runQueueJob(definition, job, queue) {
|
|
15
|
+
await runInRunScopes(async () => {
|
|
16
|
+
checkQueueHandlerResponse(await runWithTimeout(definition, job, queue));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/** Runs one attempt of a Queue handler inside the run scopes, with its timeout. Returns what the handler returned. */
|
|
20
|
+
function runQueueHandler(definition, job, queue) {
|
|
21
|
+
return runInRunScopes(() => runWithTimeout(definition, job, queue));
|
|
22
|
+
}
|
|
23
|
+
async function runWithTimeout(definition, job, queue) {
|
|
24
|
+
const timeout = definition.timeout ?? defaultQueueTimeout;
|
|
25
|
+
const deadline = performance.now() + Math.ceil(parseDuration(timeout, "timeout"));
|
|
26
|
+
const controller = new AbortController();
|
|
27
|
+
const abort = () => {
|
|
28
|
+
const error = queueErrorDiagnostics.QUEUE_JOB_TIMEOUT({
|
|
29
|
+
queue,
|
|
30
|
+
timeout: String(timeout)
|
|
31
|
+
});
|
|
32
|
+
controller.abort(error);
|
|
33
|
+
return error;
|
|
34
|
+
};
|
|
35
|
+
let timer;
|
|
36
|
+
const expired = new Promise((_resolve, reject) => {
|
|
37
|
+
const arm = () => {
|
|
38
|
+
timer = setTimeout(() => {
|
|
39
|
+
if (performance.now() < deadline) return arm();
|
|
40
|
+
reject(abort());
|
|
41
|
+
}, Math.min(Math.max(Math.ceil(deadline - performance.now()), 1), maxTimerDelay));
|
|
42
|
+
timer.unref?.();
|
|
43
|
+
};
|
|
44
|
+
arm();
|
|
45
|
+
});
|
|
46
|
+
const run = (async () => {
|
|
47
|
+
const result = await definition.handler({
|
|
48
|
+
...job,
|
|
49
|
+
signal: controller.signal
|
|
50
|
+
});
|
|
51
|
+
if (controller.signal.aborted) throw controller.signal.reason;
|
|
52
|
+
if (performance.now() >= deadline) throw abort();
|
|
53
|
+
return result;
|
|
54
|
+
})();
|
|
55
|
+
try {
|
|
56
|
+
return await Promise.race([run, expired]);
|
|
57
|
+
} finally {
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export { runQueueJob as n, runQueueHandler as t };
|
package/dist/runtime/hosted.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as QueueDefinition } from "../types-rZHAtkK0.js";
|
|
2
2
|
export declare const hostedVercelWaitUntil: (promise: Promise<unknown>) => void | undefined;
|
|
3
3
|
/** Handle one Vercel Queue delivery. The generated consumer route is a Fetchable module that passes its Request here. */
|
|
4
4
|
export declare function handleHostedVercelQueueCallback(request: Request, name: string, definition: QueueDefinition): Promise<Response>;
|
package/dist/runtime/hosted.js
CHANGED
|
@@ -1,49 +1,61 @@
|
|
|
1
|
-
import { t as queueErrorDiagnostics } from "../error-diagnostics-
|
|
2
|
-
import { i as reportQueueDeliveryError, r as isNonRetryableQueueError
|
|
3
|
-
import { n as
|
|
4
|
-
import {
|
|
1
|
+
import { t as queueErrorDiagnostics } from "../error-diagnostics-Yj8XCiya.js";
|
|
2
|
+
import { i as reportQueueDeliveryError, r as isNonRetryableQueueError } from "../handler-response-DKhsmxDV.js";
|
|
3
|
+
import { n as queueRetryPolicy } from "../retries-BSAZru9n.js";
|
|
4
|
+
import { n as runQueueJob } from "../run-handler-COXFYL5z.js";
|
|
5
|
+
import { r as loadQueueClient } from "../client-mT8TUaag.js";
|
|
5
6
|
import { waitUntil } from "@vercel/functions";
|
|
6
7
|
// src/runtime/hosted.ts
|
|
7
8
|
const hostedVercelWaitUntil = waitUntil;
|
|
8
|
-
|
|
9
|
+
const vercelMaxRetryDelaySeconds = 3600;
|
|
10
|
+
function vercelDeliveryMetadata(metadata) {
|
|
11
|
+
return metadata;
|
|
12
|
+
}
|
|
13
|
+
function createVercelJobHandler(name, definition, limit) {
|
|
9
14
|
return async (payload, metadata) => {
|
|
10
|
-
const meta = metadata;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
15
|
+
const meta = vercelDeliveryMetadata(metadata);
|
|
16
|
+
const attempts = meta?.deliveryCount ?? 1;
|
|
17
|
+
if (attempts > limit + 1) return;
|
|
18
|
+
await runQueueJob(definition, {
|
|
19
|
+
attempts,
|
|
20
|
+
id: meta?.messageId ?? "vercel-message",
|
|
21
|
+
metadata,
|
|
22
|
+
payload
|
|
23
|
+
}, name);
|
|
19
24
|
};
|
|
20
25
|
}
|
|
21
|
-
function createVercelCallbackOptions(name,
|
|
26
|
+
function createVercelCallbackOptions(name, definition, retries) {
|
|
27
|
+
const options = definition.callbackOptions;
|
|
22
28
|
const retry = options?.retry;
|
|
23
29
|
return {
|
|
24
30
|
...options,
|
|
25
31
|
retry(error, metadata) {
|
|
26
|
-
const meta = metadata;
|
|
32
|
+
const meta = vercelDeliveryMetadata(metadata);
|
|
33
|
+
const attempts = Math.max(1, meta?.deliveryCount ?? 1);
|
|
27
34
|
reportQueueDeliveryError(error, {
|
|
28
|
-
attempts
|
|
29
|
-
id:
|
|
35
|
+
attempts,
|
|
36
|
+
id: meta?.messageId ?? "vercel-message",
|
|
30
37
|
provider: "vercel",
|
|
31
38
|
queue: name
|
|
32
39
|
});
|
|
40
|
+
if (attempts > retries.limit) return { acknowledge: true };
|
|
33
41
|
const directive = retry?.(error, metadata);
|
|
34
42
|
if (directive !== void 0) return directive;
|
|
35
43
|
if (isNonRetryableQueueError(error)) return { acknowledge: true };
|
|
44
|
+
const remainingSeconds = meta?.expiresAt ? Math.floor((meta.expiresAt.getTime() - Date.now()) / 1e3) - 1 : vercelMaxRetryDelaySeconds;
|
|
45
|
+
if (remainingSeconds < 0) return { acknowledge: true };
|
|
46
|
+
return { afterSeconds: Math.min(Math.ceil(retries.delayMs(attempts) / 1e3), vercelMaxRetryDelaySeconds, remainingSeconds) };
|
|
36
47
|
}
|
|
37
48
|
};
|
|
38
49
|
}
|
|
39
50
|
/** Handle one Vercel Queue delivery. The generated consumer route is a Fetchable module that passes its Request here. */
|
|
40
51
|
async function handleHostedVercelQueueCallback(request, name, definition) {
|
|
41
|
-
const queue = await
|
|
52
|
+
const queue = await loadQueueClient(name);
|
|
42
53
|
if (queue.provider !== "vercel") throw queueErrorDiagnostics.QUEUE_DRIVER_MISMATCH({
|
|
43
54
|
driver: queue.provider,
|
|
44
55
|
expected: "vercel"
|
|
45
56
|
});
|
|
46
|
-
const
|
|
57
|
+
const retries = queueRetryPolicy(definition.retries);
|
|
58
|
+
const result = await queue.callback(createVercelJobHandler(name, definition, retries.limit), createVercelCallbackOptions(name, definition, retries))(request);
|
|
47
59
|
if (result instanceof Response) return result;
|
|
48
60
|
return result === void 0 ? new Response(null, { status: 204 }) : Response.json(result);
|
|
49
61
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { r as readSourceText, t as deriveFromSource } from "./source-files-DrAH1-c8.js";
|
|
1
2
|
import { parseSync } from "vite";
|
|
2
3
|
// ../internal/src/build/ast-walk.ts
|
|
3
4
|
/** The oxc parser grammar for a file, from its extension. Defaults to TypeScript. */
|
|
@@ -45,8 +46,22 @@ function scanModule(source, file = "module.ts") {
|
|
|
45
46
|
source
|
|
46
47
|
};
|
|
47
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Reads and parses a source file once for each change of its text. Callers share the result, so they must not change
|
|
51
|
+
* the syntax tree.
|
|
52
|
+
*/
|
|
53
|
+
function scanSourceFile(file) {
|
|
54
|
+
return scanModuleText(readSourceText(file), file);
|
|
55
|
+
}
|
|
56
|
+
/** `scanModule` with a result that is shared while `source` stays the same for `file`. */
|
|
57
|
+
function scanModuleText(source, file) {
|
|
58
|
+
return deriveFromSource("scan-module", file, source, () => scanModule(source, file));
|
|
59
|
+
}
|
|
48
60
|
/** Lists the names that a module exports. A default export reads as `default`. Type-only exports are left out. */
|
|
49
61
|
function exportNames(source, file = "module.ts") {
|
|
62
|
+
return [...deriveFromSource("export-names", file, source, () => readExportNames(source, file))];
|
|
63
|
+
}
|
|
64
|
+
function readExportNames(source, file) {
|
|
50
65
|
const { module } = parseSync(file, source, {
|
|
51
66
|
lang: moduleLanguage(file),
|
|
52
67
|
sourceType: "module"
|
|
@@ -306,4 +321,4 @@ function templateExpressionSources(template) {
|
|
|
306
321
|
if (literal.type !== "TemplateLiteral") return [];
|
|
307
322
|
return literal.expressions.map((_node, index) => module.source.slice(literal.quasis[index]?.end ?? 0, literal.quasis[index + 1]?.start ?? 0));
|
|
308
323
|
}
|
|
309
|
-
export { argumentExpression, defaultExportExpression, dynamic, exportNames, findCalls, findDefaultExportCall, findProperty, maskLiterals, moduleTokens, nodeText, objectProperties, scanModule, staticString, staticValue, templateExpressionSources, unwrapExpression, walk };
|
|
324
|
+
export { argumentExpression, defaultExportExpression, dynamic, exportNames, findCalls, findDefaultExportCall, findProperty, maskLiterals, moduleTokens, nodeText, objectProperties, scanModule, scanModuleText, scanSourceFile, staticString, staticValue, templateExpressionSources, unwrapExpression, walk };
|