@vite-hub/schedule 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 +27 -6
- package/dist/cron-D0mqg3ql.js +22 -0
- package/dist/definition.d.ts +1 -1
- package/dist/definition.js +3 -4
- package/dist/{due-D-0trD1g.js → due-DXgXKgzg.js} +1 -1
- package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
- package/dist/{error-diagnostics-B1AaIGWP.js → error-diagnostics-KvK9MX6w.js} +14 -2
- package/dist/{started-errors-IG9DlT2A.js → execute-DoQC2i_V.js} +7 -34
- package/dist/index.d.ts +12 -8
- package/dist/index.js +1 -51
- package/dist/{kv-storage-hI2IOjb5.d.ts → kv-storage-CKSSQ6Fk.d.ts} +7 -3
- package/dist/{kv-storage-Dsr3TL9c.js → kv-storage-CszEkof6.js} +2 -2
- package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-Blwi3jQF.d.ts} +1 -0
- package/dist/{operations-BTUQeba1.js → operations-CEZCefAG.js} +25 -13
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +7 -5
- package/dist/os.js +2 -2
- package/dist/runtime/console.js +24 -11
- package/dist/runtime/kv.d.ts +1 -1
- package/dist/runtime/kv.js +1 -1
- package/dist/runtime/process.d.ts +1 -1
- package/dist/runtime/process.js +14 -16
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/state.js +1 -1
- package/dist/runtime/static.d.ts +1 -1
- package/dist/runtime/static.js +2 -2
- package/dist/runtime.d.ts +6 -6
- package/dist/runtime.js +5 -5
- package/dist/{started-B1Se_Iwo.js → started-ClJ5XOWH.js} +48 -9
- package/dist/started-errors-DVw5cYHR.js +28 -0
- package/dist/{started-Bzvr4t5f.js → started-yb49f37g.js} +6 -4
- package/dist/state-CcVY3UzB.js +570 -0
- package/dist/{state-BDEDVlyr.d.ts → state-LuEgYpwR.d.ts} +1 -1
- package/dist/{static-Bg7Jj92L.js → static--wi-oIIb.js} +7 -5
- package/dist/{static-DeRvJqcQ.d.ts → static-BFV4x94g.d.ts} +1 -1
- package/dist/{store-CEv3cScg.d.ts → store-TOayO0NL.d.ts} +6 -3
- package/dist/{types-DTVPVY5O.d.ts → types-Wllh0U8N.d.ts} +35 -4
- package/dist/vite.d.ts +4 -2
- package/dist/vite.js +377 -118
- package/package.json +10 -4
- package/dist/started-name-w6n9uDdt.js +0 -4
- package/dist/state-BZLy46UJ.js +0 -427
- package/dist/{cron-BT3ef48f.js → cron-imqlBgO-.js} +1 -1
package/README.md
CHANGED
|
@@ -104,7 +104,7 @@ export default defineSchedule({
|
|
|
104
104
|
|
|
105
105
|
Static Schedule Definitions use five-field cron expressions. The cron uses UTC unless the definition sets `timeZone` to an IANA name, such as `Europe/Madrid`. `timeZone` works with the Process Runtime and with every host's cron output.
|
|
106
106
|
|
|
107
|
-
The integration can generate host-specific output for Cloudflare Cron Triggers, Vercel Cron Jobs, Netlify Scheduled Functions, standalone `Deno.cron`, Nitro's Cloudflare schedule hook, and Netlify Scheduled Functions that run in Nitro's server bundle. A build writes only the output of its host: Nitro's resolved preset, or else `nitro.preset`, `NITRO_PRESET`, `SERVER_PRESET`, or `VITEHUB_HOST`. It writes the output of every host only when no host is known. Host selection, local execution, deployment proof, limits, and billing still come from the selected host. Check the [runtime and host support matrix](https://vitehub.dev/docs/frameworks-hosts/support-matrix) before deploying. Write weekdays as standard cron numbers, 0 to 6 from Sunday. Cloudflare and Deno number weekdays 1 to 7 from Sunday, so their output writes weekday names: `0 4 * * 1-5` becomes `0 4 * * MON,TUE,WED,THU,FRI`.
|
|
107
|
+
The integration can generate host-specific output for Cloudflare Cron Triggers, Vercel Cron Jobs, Netlify Scheduled Functions, standalone `Deno.cron`, Nitro's Cloudflare schedule hook, Vercel cron routes in Nitro's server function, and Netlify Scheduled Functions that run in Nitro's server bundle. A build writes only the output of its host: Nitro's resolved preset, or else `nitro.preset`, `NITRO_PRESET`, `SERVER_PRESET`, or `VITEHUB_HOST`. It writes the output of every host only when no host is known. Host selection, local execution, deployment proof, limits, and billing still come from the selected host. Check the [runtime and host support matrix](https://vitehub.dev/docs/frameworks-hosts/support-matrix) before deploying. Write weekdays as standard cron numbers, 0 to 6 from Sunday. Cloudflare and Deno number weekdays 1 to 7 from Sunday, so their output writes weekday names: `0 4 * * 1-5` becomes `0 4 * * MON,TUE,WED,THU,FRI`.
|
|
108
108
|
|
|
109
109
|
Applications that use the framework distribution turn Schedule on with a file in `server/schedules/`, with no `schedule` key, and import the definition helper from `vite-hub/schedule`. On Deno, the build writes standalone cron output and a `.output/main.ts` entrypoint that loads it before the Nitro server.
|
|
110
110
|
|
|
@@ -134,6 +134,8 @@ const [, started] = await listSchedules({ name: "reminder" });
|
|
|
134
134
|
await cancelSchedule(standUp!.id);
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
+
The build writes the discovered names to `.vitehub/schedule.d.ts`. `runSchedule()` takes a `ScheduleName` (a Definition with `cron`), and `startSchedule()` takes a `StartableScheduleName` (a Definition without `cron`), so a typo fails typecheck. A `string` that code reads at runtime still type-checks.
|
|
138
|
+
|
|
137
139
|
The functions return `[error, data]`. The Schedules are stored in KV, so they survive restarts and deploys. When a Definition has no `cron`, the build adds the Schedule `vitehub/started-schedules` with the cron `* * * * *`: Cloudflare wakes it with a Cron Trigger, and the Process Runtime wakes it on Node. Each wake runs the started Schedules that are due. Started Schedules need KV, and on Node the Process Runtime. `vitehub schedule start` and `cancel` and the Console Schedules page show and change them. `vitehub schedule list` lists them after the Static Schedule Definitions, and works without KV when no Definition can be started. Read the [server API](https://vitehub.dev/docs/schedule/server-api#start-a-schedule-from-code) for the delivery rules.
|
|
138
140
|
|
|
139
141
|
## Understand time zones
|
|
@@ -247,13 +249,30 @@ const scheduleRunStore = createKVScheduleRunStore({ kvStore: scheduleKVStorage }
|
|
|
247
249
|
|
|
248
250
|
Generated Process Runtime wiring selects this adapter automatically. Applications using the framework can import it from `vite-hub/schedule/runtime/kv`. Use `setScheduleRunStore(store)` to install a custom `ScheduleRunStore`.
|
|
249
251
|
|
|
250
|
-
|
|
252
|
+
### Keep run history for a limited time
|
|
253
|
+
|
|
254
|
+
The KV store starts the `retention` TTL after a run finishes and a newer run of the same Schedule and source replaces it, in either order. One-shot Schedules (`startSchedule(name, { at })`) start the TTL when their run finishes. Pending and running records have no TTL. The newest run of each repeating Schedule and source stays available for catch-up.
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
import { createKVScheduleRunStore } from "@vite-hub/schedule/runtime"
|
|
258
|
+
import { scheduleKVStorage } from "@vite-hub/schedule/runtime/kv"
|
|
259
|
+
import { hubSchedule } from "@vite-hub/schedule/vite"
|
|
260
|
+
|
|
261
|
+
hubSchedule({ retention: "7 days", runtime: { driver: "process" } })
|
|
262
|
+
createKVScheduleRunStore({ kvStore: scheduleKVStorage, retention: "7 days" })
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
`retention` defaults to 30 days or `runtime.catchUpMs`, whichever is longer. An explicit value must be longer than zero and not shorter than `runtime.catchUpMs`, or the build fails with `SCHEDULE_RETENTION_TOO_SHORT`. A new value applies to runs whose TTL starts after the change. Cloudflare KV deletes a value at the earliest 60 seconds after it is written. A custom `ScheduleKVStorage` that ignores the `ttl` option of `set()` keeps every run. The memory store keeps runs until the process stops.
|
|
266
|
+
|
|
267
|
+
Custom stores must apply the `listRuns({ scheduleId, idPrefix, limit })` filters before the limit. The KV store answers the Process Runtime's `listRuns({ scheduleId, idPrefix: "srun_static_", limit: 1 })` lookup with at most two key reads and no listing. General history queries still list index keys.
|
|
268
|
+
|
|
269
|
+
When upgrading an existing shared KV store to retention, stop all old Schedule processes and writers before starting the new version. Back up the KV store, start one new process and let it open the run history before starting other replicas. The first history access rebuilds the indexes and removes the old layout. Do not mix versions against the same KV prefix.
|
|
251
270
|
|
|
252
271
|
## Run and inspect schedules
|
|
253
272
|
|
|
254
|
-
`hubSchedule()` contributes the `schedule.runs`, `schedule.attempts`, `schedule.run`, `schedule.list`, `schedule.start`, and `schedule.cancel` operations. They are the `vitehub schedule runs list
|
|
273
|
+
`hubSchedule()` contributes the `schedule.runs`, `schedule.attempts`, `schedule.run`, `schedule.list`, `schedule.start`, and `schedule.cancel` operations. They are the `vitehub schedule runs list [id] [--limit <n>]`, `runs get <runId>`, `run <name>`, `list [name]`, `start <name>`, and `cancel <id>` commands, and the Console runs them too. Each command accepts `--json` and `--url`. Without `--url` the command calls the dev server of the project, whose Nitro runtime owns the same stores and registry as the running app.
|
|
255
274
|
|
|
256
|
-
|
|
275
|
+
Every Static Schedule Definition can run on demand with `vitehub schedule run <name>`. Set `manual: false` to allow only its cron. The name is the discovered schedule file name. Add `--url <app-url>` to run it on a deployment that enables `console.invoke`. The command signs the call with `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>`, so a CI job needs only that secret. `vitehub secret console-key ci` prints a new key pair. Server code can call `runSchedule(name)` from `@vite-hub/schedule`. It reads the generated registry and returns `[error, run]`. A failed handler gives a run with `status: "failed"`. An invalid `scheduledAt` or a failed run store gives `error`. An unknown name or a Definition with `manual: false` throws. Each manual run gets a new `srun_manual_` id.
|
|
257
276
|
|
|
258
277
|
Add `--at <ISO date-time>` to run it as if the cron fired at that time, for example `vitehub schedule run close-month --at 2026-01-31T23:59:00Z`. The handler gets the time as `scheduledAt`, and the run records it, so `vitehub schedule runs list` lists it under that time. `runSchedule()` takes the same value as `scheduledAt`. The value needs `Z` or an offset. A value without a time zone, a date only, or a day that does not exist fails with `SCHEDULE_INVALID_SCHEDULED_AT` before the handler runs. `runSchedule()` returns it as `error`. The time is not checked against the cron. Manual runs do not advance the Process Runtime's catch-up cursor, even when their scheduled time is in the future.
|
|
259
278
|
|
|
@@ -263,7 +282,9 @@ The Console Schedules section lists Schedule Definitions with their cron, time z
|
|
|
263
282
|
|
|
264
283
|
## Runs in logs
|
|
265
284
|
|
|
266
|
-
With the evlog Nitro module registered, each Schedule handler run inside Nitro gets its own evlog event, `schedule: { name, source, scheduledAt, ms, outcome }`, with the error when it fails. Standalone provider wakes do not send these events. This includes
|
|
285
|
+
With the evlog Nitro module registered, each Schedule handler run inside Nitro gets its own evlog event, `schedule: { name, source, scheduledAt, ms, outcome }`, with the error when it fails. Standalone provider wakes do not send these events. This includes Deno cron wakes by default, and Cloudflare, Vercel, or Netlify when you select standalone output. Without evlog, failures go to the console. See [Server API](https://vitehub.dev/docs/schedule/server-api#see-schedule-runs-in-logs).
|
|
286
|
+
|
|
287
|
+
On Cloudflare, static cron runs do not appear in the CLI or Console, even in the same Worker isolate. Records for manual runs and runs of Schedules started with `startSchedule()` stay in the isolate that wrote them, even with KV. The build prints `SCHEDULE_RUNS_IN_WORKER_MEMORY` to explain this limit.
|
|
267
288
|
|
|
268
289
|
## Import runtime helpers
|
|
269
290
|
|
|
@@ -280,4 +301,4 @@ Static Schedule execution logs each failed handler as `[vitehub:schedule] Schedu
|
|
|
280
301
|
- Check [runtime and host support](https://vitehub.dev/docs/frameworks-hosts/support-matrix) for current proof and host qualifications.
|
|
281
302
|
- Report package problems in the [ViteHub issue tracker](https://github.com/vite-hub/vitehub/issues).
|
|
282
303
|
|
|
283
|
-
|
|
304
|
+
The Process Runtime uses [`cron-schedule`](https://github.com/P4sca1/cron-schedule). Vite uses the same parser to check literal crons for Schedules run by the Process Runtime in dev and at build time. The Process Runtime checks computed crons when it loads their Definitions. A cron the parser cannot read, such as one with `L` or `?`, fails with `SCHEDULE_CRON_UNSUPPORTED`. Provider builds check the host cron, including any override.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { t as scheduleErrorDiagnostics } from "./error-diagnostics-KvK9MX6w.js";
|
|
2
|
+
import { parseCronExpression } from "cron-schedule";
|
|
3
|
+
// src/cron.ts
|
|
4
|
+
const cronFieldPattern = /^[^\s]+$/;
|
|
5
|
+
function assertScheduleCronFields(cron, where) {
|
|
6
|
+
const fields = cron.split(/\s+/);
|
|
7
|
+
if (fields.length !== 5 || !fields.every((field) => cronFieldPattern.test(field))) throw scheduleErrorDiagnostics.SCHEDULE_C0002({ message: `${where} cron must be a five-field cron expression.` });
|
|
8
|
+
}
|
|
9
|
+
function parseScheduleCronExpression(cron, where) {
|
|
10
|
+
assertScheduleCronFields(cron, where);
|
|
11
|
+
try {
|
|
12
|
+
return parseCronExpression(cron);
|
|
13
|
+
} catch (cause) {
|
|
14
|
+
throw scheduleErrorDiagnostics.SCHEDULE_CRON_UNSUPPORTED({
|
|
15
|
+
cause,
|
|
16
|
+
cron,
|
|
17
|
+
reason: cause instanceof Error ? cause.message : String(cause),
|
|
18
|
+
where
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export { parseScheduleCronExpression as n, assertScheduleCronFields as t };
|
package/dist/definition.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as ScheduleDefinitionInput, r as ScheduleDefinition } from "./types-Wllh0U8N.js";
|
|
2
2
|
export declare function defineSchedule<TResult = unknown>(input: ScheduleDefinitionInput<TResult> & {
|
|
3
3
|
cron: string;
|
|
4
4
|
}): ScheduleDefinition<TResult> & {
|
package/dist/definition.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as isIanaTimeZone } from "./time-zone-pMp_g8Uu.js";
|
|
2
2
|
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
3
|
-
import { t as
|
|
3
|
+
import { t as assertScheduleCronFields } from "./cron-D0mqg3ql.js";
|
|
4
|
+
import { t as scheduleErrorDiagnostics } from "./error-diagnostics-KvK9MX6w.js";
|
|
4
5
|
// src/definition.ts
|
|
5
|
-
const cronFieldPattern = /^[^\s]+$/;
|
|
6
6
|
const scheduleDefinitionKeys = /* @__PURE__ */ new Set([
|
|
7
7
|
"manual",
|
|
8
8
|
"cron",
|
|
@@ -18,8 +18,7 @@ function assertOwnDefinitionFields(input, keys, message, diagnostic) {
|
|
|
18
18
|
}
|
|
19
19
|
function validateCron(cron) {
|
|
20
20
|
if (typeof cron !== "string" || cron.trim() !== cron || cron.length === 0) throw scheduleErrorDiagnostics.SCHEDULE_C0001({ message: "`defineSchedule()` requires a cron string." });
|
|
21
|
-
|
|
22
|
-
if (fields.length !== 5 || !fields.every((field) => cronFieldPattern.test(field))) throw scheduleErrorDiagnostics.SCHEDULE_C0002({ message: "`defineSchedule()` cron must be a five-field cron expression." });
|
|
21
|
+
assertScheduleCronFields(cron, "`defineSchedule()`");
|
|
23
22
|
}
|
|
24
23
|
const positionalFormMessage = "`defineSchedule(cron, handler)` was removed. Pass one object: `defineSchedule({ cron: \"0 9 * * *\", handler })`, with `manual` and `timeZone` in the same object.";
|
|
25
24
|
function defineSchedule(input, ...removed) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as scheduleErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as scheduleErrorDiagnostics } from "./error-diagnostics-KvK9MX6w.js";
|
|
2
2
|
import { parseCronExpression } from "cron-schedule";
|
|
3
3
|
// src/runtime/due.ts
|
|
4
4
|
const weekdayIndexes = /* @__PURE__ */ new Map([
|
|
@@ -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,
|
|
@@ -5,8 +5,8 @@ const scheduleErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
5
5
|
docsBase: "https://vitehub.dev/docs/schedule/diagnostics",
|
|
6
6
|
codes: {
|
|
7
7
|
SCHEDULE_DEFINITION_NOT_FOUND: {
|
|
8
|
-
why: "
|
|
9
|
-
fix: "
|
|
8
|
+
why: "The app has no Static Schedule Definition with this name, or the Console cannot run Schedules because `console.invoke` is off.",
|
|
9
|
+
fix: "Pass the file name of a Schedule with `cron` in `server/schedules/`, such as `daily-report`. For a deployed app, set `console: { invoke: true }` (it is on in development)."
|
|
10
10
|
},
|
|
11
11
|
SCHEDULE_OPERATION_FAILED: {
|
|
12
12
|
why: "Schedule operation failed.",
|
|
@@ -148,6 +148,10 @@ const scheduleErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
148
148
|
...dynamicError,
|
|
149
149
|
fix: "Set Schedule `runtime.leaseTtlMs` to a finite number greater than zero, or omit it to use the 60000 ms default."
|
|
150
150
|
},
|
|
151
|
+
SCHEDULE_CRON_UNSUPPORTED: {
|
|
152
|
+
why: ({ cron, reason, where }) => `${where} uses cron "${cron}", which the Schedule runtime cannot read: ${reason}`,
|
|
153
|
+
fix: "Write `cron` with numbers, `*`, `,`, `-`, and `/`, such as `\"0 9 * * 1-5\"`. `L` and `?` are not supported. To run on the last day of a month, run on days 28-31 and return early in the handler when tomorrow is not the 1st."
|
|
154
|
+
},
|
|
151
155
|
SCHEDULE_DEFINITION_EXPORT_INVALID: {
|
|
152
156
|
why: ({ name }) => `Schedule "${name}" has no default export of defineSchedule() with a cron and a handler.`,
|
|
153
157
|
fix: "Default-export `defineSchedule({ cron, handler })` from the Schedule file that the message names, in `server/schedules/`."
|
|
@@ -156,6 +160,14 @@ const scheduleErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
156
160
|
why: "The Process Runtime claims each Schedule occurrence in memory, because the app has no Database. With several server processes, each one runs every occurrence.",
|
|
157
161
|
fix: "Run one server only, or add a Postgres Database so that more than one server runs each occurrence once."
|
|
158
162
|
},
|
|
163
|
+
SCHEDULE_RETENTION_TOO_SHORT: {
|
|
164
|
+
why: ({ catchUpMs, retention }) => `Schedule \`retention\` is ${retention}, which is zero or shorter than the ${catchUpMs} ms that catch-up and restart recovery read back.`,
|
|
165
|
+
fix: "Set `retention` in `hubSchedule()` or in `vitehub({ schedule })` to a duration longer than zero and not shorter than `runtime.catchUpMs`, or remove it to use the greater of 30 days and `runtime.catchUpMs`."
|
|
166
|
+
},
|
|
167
|
+
SCHEDULE_RUNS_IN_WORKER_MEMORY: {
|
|
168
|
+
why: "Static cron runs do not appear in `vitehub schedule runs` or the Console. The Worker keeps records for manual runs and runs of Schedules started with `startSchedule()` only in the isolate that wrote them, even with KV. The records are lost when that isolate stops.",
|
|
169
|
+
fix: "Write what a run must keep, such as its result, to a Database or KV from its handler."
|
|
170
|
+
},
|
|
159
171
|
SCHEDULE_RUNTIME_CATCH_UP_INVALID: {
|
|
160
172
|
why: "Schedule Process Runtime catchUpMs must be a non-negative number.",
|
|
161
173
|
fix: "Set `runtime.catchUpMs` in `hubSchedule()` or in `vitehub({ schedule })` to a number of 0 or more, or remove it to use one hour (`3600000`)."
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { C as createScheduleError, S as validateScheduledAt, _ as emitLogEvent, b as parseScheduledAt, c as markLoggedScheduleError, d as normalizeScheduleRuntimeError, g as logScheduleRun, h as runWithScheduleWaitUntil, v as errorCode, x as scheduleIdempotencyKey } from "./static--wi-oIIb.js";
|
|
1
2
|
import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
|
|
2
|
-
import {
|
|
3
|
-
import { i as getScheduleRunStore } from "./state-BZLy46UJ.js";
|
|
4
|
-
import { defineErrors } from "@vite-hub/runtime";
|
|
3
|
+
import { i as getScheduleRunStore } from "./state-CcVY3UzB.js";
|
|
5
4
|
import { serializeResponse, toResponse } from "@vite-hub/runtime/internal/response";
|
|
6
5
|
import { emitRunFailed, toRunFailedError } from "@vite-hub/runtime/internal/run-failed";
|
|
7
6
|
import { runInRunScopes } from "@vite-hub/runtime/internal/run-scope";
|
|
@@ -60,7 +59,7 @@ async function createOrGetRun(options) {
|
|
|
60
59
|
try {
|
|
61
60
|
return {
|
|
62
61
|
created: true,
|
|
63
|
-
run: await store.createRun(runInput)
|
|
62
|
+
run: options.oneShot ? await store.createRun(runInput, { oneShot: true }) : await store.createRun(runInput)
|
|
64
63
|
};
|
|
65
64
|
} catch (error) {
|
|
66
65
|
const run = await store.getRun(id);
|
|
@@ -236,7 +235,7 @@ async function executeStaticSchedule(options) {
|
|
|
236
235
|
});
|
|
237
236
|
}
|
|
238
237
|
function isStaticScheduleDefinition(value) {
|
|
239
|
-
return isRecordOrFunction(value) && Object.hasOwn(value, "handler") && typeof value.handler === "function" && Object.hasOwn(value, "cron");
|
|
238
|
+
return isRecordOrFunction(value) && Object.hasOwn(value, "handler") && typeof value.handler === "function" && Object.hasOwn(value, "cron") && typeof value.cron === "string";
|
|
240
239
|
}
|
|
241
240
|
async function loadStaticScheduleDefinition(name, registry) {
|
|
242
241
|
const entry = Object.hasOwn(registry, name) ? registry[name] : void 0;
|
|
@@ -247,7 +246,7 @@ async function loadStaticScheduleDefinition(name, registry) {
|
|
|
247
246
|
async function resolveManualSchedule(registry, name) {
|
|
248
247
|
const definition = typeof name === "string" && name ? await loadStaticScheduleDefinition(name, registry) : void 0;
|
|
249
248
|
if (!definition) throw createScheduleError("SCHEDULE_DEFINITION_NOT_FOUND");
|
|
250
|
-
if (definition.options?.manual
|
|
249
|
+
if (definition.options?.manual === false) throw createScheduleError("SCHEDULE_MANUAL_RUN_DISABLED");
|
|
251
250
|
return definition;
|
|
252
251
|
}
|
|
253
252
|
function executeManualSchedule(definition, name, scheduledAt) {
|
|
@@ -261,34 +260,8 @@ function executeManualSchedule(definition, name, scheduledAt) {
|
|
|
261
260
|
target: name
|
|
262
261
|
});
|
|
263
262
|
}
|
|
264
|
-
/** Runs a
|
|
263
|
+
/** Runs a Static Schedule Definition of `registry` immediately, unless it sets `manual: false`. */
|
|
265
264
|
async function runScheduleFrom(registry, name, options = {}) {
|
|
266
265
|
return await executeManualSchedule(await resolveManualSchedule(registry, name), name, parseScheduledAt(options.scheduledAt));
|
|
267
266
|
}
|
|
268
|
-
|
|
269
|
-
const startedScheduleErrors = /*#__PURE__*/ defineErrors({
|
|
270
|
-
docs: "https://vitehub.dev/docs/schedule/diagnostics",
|
|
271
|
-
codes: {
|
|
272
|
-
SCHEDULE_NOT_STARTABLE: {
|
|
273
|
-
why: ({ name }) => `No Schedule Definition without \`cron\` is named "${name}", so \`startSchedule()\` cannot start it.`,
|
|
274
|
-
fix: "Add `server/schedules/<name>.ts` with `export default defineSchedule({ handler })` and no `cron`. A Definition with its own `cron` runs only on that cron."
|
|
275
|
-
},
|
|
276
|
-
SCHEDULE_INVALID_OPTIONS: {
|
|
277
|
-
why: ({ problem }) => `\`startSchedule()\` options are invalid: ${problem}`,
|
|
278
|
-
fix: "Pass `{ at }` for one run, or `{ cron, timeZone }` for a repeating Schedule, and a JSON `payload`."
|
|
279
|
-
},
|
|
280
|
-
SCHEDULE_NOT_FOUND: {
|
|
281
|
-
why: ({ id }) => `No started Schedule has the id "${id}". It ran its last time, was cancelled, or never existed.`,
|
|
282
|
-
fix: "List the started Schedules with `listSchedules()` or `vitehub schedule list`."
|
|
283
|
-
},
|
|
284
|
-
SCHEDULE_STORE_MISSING: {
|
|
285
|
-
why: "This server has no store for started Schedules.",
|
|
286
|
-
fix: "Add a Schedule Definition without `cron` in `server/schedules/`, enable `kv`, and build with Nitro. On Node, also set `schedule: { runtime: { driver: \"process\" } }`."
|
|
287
|
-
},
|
|
288
|
-
SCHEDULE_STORE_FAILED: {
|
|
289
|
-
why: "The store of started Schedules failed. `error.cause` has the store error.",
|
|
290
|
-
fix: "Check that KV is enabled and reachable from this server, then try again."
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
export { executeStaticSchedule as a, runScheduleFrom as c, executeSchedule as i, toRunId as l, createScheduleRun as n, loadStaticScheduleDefinition as o, executeManualSchedule as r, resolveManualSchedule as s, startedScheduleErrors as t, randomId as u };
|
|
267
|
+
export { loadStaticScheduleDefinition as a, toRunId as c, executeStaticSchedule as i, randomId as l, executeManualSchedule as n, resolveManualSchedule as o, executeSchedule as r, runScheduleFrom as s, createScheduleRun as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference path="./registry-module.d.ts" />
|
|
2
2
|
import { defineSchedule } from "./definition.js";
|
|
3
|
-
import { i as RunScheduleOptions, t as KVScheduleStoreOptions } from "./store-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { i as RunScheduleOptions, t as KVScheduleStoreOptions } from "./store-TOayO0NL.js";
|
|
4
|
+
import { C as StartableScheduleName, E as StartedScheduleStore, S as StartScheduleTiming, T as StartedSchedule, _ as ScheduleRunRecord, b as ScheduleRunStore, c as ScheduleName, d as ScheduleRegistryState, f as ScheduleRunAttemptRecord, g as ScheduleRunListOptions, h as ScheduleRunError, i as ScheduleDefinitionInput, l as ScheduleRegistry, m as ScheduleRunContext, n as DynamicScheduleName, o as ScheduleDefinitionRegistry, p as ScheduleRunAttemptStatus, r as ScheduleDefinition, s as ScheduleHandler, t as DiscoveredScheduleDefinition, u as ScheduleRegistryDefinition, v as ScheduleRunResponse, w as StartableScheduleRegistry, x as StartScheduleOptions, y as ScheduleRunStatus } from "./types-Wllh0U8N.js";
|
|
5
|
+
import { n as ScheduleKVStorage, t as ScheduleKVSetOptions } from "./kv-storage-CKSSQ6Fk.js";
|
|
6
6
|
import { ErrorCatalog, Result, ViteHubError } from "@vite-hub/runtime";
|
|
7
7
|
type RunScheduleErrorCodes = {
|
|
8
8
|
SCHEDULE_INVALID_SCHEDULED_AT: {
|
|
@@ -16,11 +16,13 @@ type RunScheduleErrorCodes = {
|
|
|
16
16
|
};
|
|
17
17
|
type RunScheduleErrorCode = keyof RunScheduleErrorCodes;
|
|
18
18
|
/**
|
|
19
|
-
* Runs a Static Schedule Definition
|
|
19
|
+
* Runs a Static Schedule Definition now, as if its cron fired at `scheduledAt` (default: now).
|
|
20
20
|
* It returns `[error, run]`. A failed handler is a run with `status: "failed"`, not an error. An invalid `scheduledAt`
|
|
21
|
-
* or a failed run store is `error`. Definition loading errors, unknown names, and Definitions
|
|
21
|
+
* or a failed run store is `error`. Definition loading errors, unknown names, and Definitions with `manual: false` throw.
|
|
22
22
|
*/
|
|
23
|
-
export declare function runSchedule(name:
|
|
23
|
+
export declare function runSchedule(name: ScheduleName, options?: RunScheduleOptions): Promise<Result<ScheduleRunRecord, RunScheduleErrorCode>>;
|
|
24
|
+
/** Runs the Static Schedule Definition with a name that the code reads at runtime. An unknown name throws. */
|
|
25
|
+
export declare function runSchedule<TName extends string>(name: DynamicScheduleName<TName>, options?: RunScheduleOptions): Promise<Result<ScheduleRunRecord, RunScheduleErrorCode>>;
|
|
24
26
|
type StartedScheduleErrorCodes = {
|
|
25
27
|
SCHEDULE_INVALID_OPTIONS: {
|
|
26
28
|
fix: string;
|
|
@@ -55,7 +57,9 @@ type StartedScheduleErrorCode = keyof StartedScheduleErrorCodes;
|
|
|
55
57
|
* occurrence of `cron` in `timeZone` until `cancelSchedule()`. The store keeps it across restarts and deploys. The handler
|
|
56
58
|
* receives `payload` as `context.payload`.
|
|
57
59
|
*/
|
|
58
|
-
export declare function startSchedule(name:
|
|
60
|
+
export declare function startSchedule(name: StartableScheduleName, options: StartScheduleOptions): Promise<Result<StartedSchedule, StartedScheduleErrorCode>>;
|
|
61
|
+
/** Starts the Schedule Definition without `cron` with a name that the code reads at runtime. */
|
|
62
|
+
export declare function startSchedule<TName extends string>(name: DynamicScheduleName<TName>, options: StartScheduleOptions): Promise<Result<StartedSchedule, StartedScheduleErrorCode>>;
|
|
59
63
|
/** Reads one started Schedule. */
|
|
60
64
|
export declare function getSchedule(id: string): Promise<Result<StartedSchedule, StartedScheduleErrorCode>>;
|
|
61
65
|
/** Lists the started Schedules, oldest first. `name` keeps the Schedules of one Definition. */
|
|
@@ -75,4 +79,4 @@ type ScheduleErrorDetails = {
|
|
|
75
79
|
field: ScheduleErrorField;
|
|
76
80
|
valueType: ScheduleErrorValueType;
|
|
77
81
|
};
|
|
78
|
-
export { type DiscoveredScheduleDefinition, type KVScheduleStoreOptions, type RunScheduleErrorCode, type RunScheduleOptions, type ScheduleDefinition, type ScheduleDefinitionInput, type ScheduleDefinitionRegistry, type ScheduleErrorCode, type ScheduleErrorDetails, type ScheduleErrorField, type ScheduleErrorValueType, type ScheduleHandler, type ScheduleKVStorage, type ScheduleRegistryDefinition, type ScheduleRunAttemptRecord, type ScheduleRunAttemptStatus, type ScheduleRunContext, type ScheduleRunError, type ScheduleRunListOptions, type ScheduleRunRecord, type ScheduleRunResponse, type ScheduleRunStatus, type ScheduleRunStore, type ScheduleValidationErrorCode, type StartScheduleOptions, type StartScheduleTiming, type StartedSchedule, type StartedScheduleErrorCode, type StartedScheduleStore, defineSchedule };
|
|
82
|
+
export { type DiscoveredScheduleDefinition, type DynamicScheduleName, type KVScheduleStoreOptions, type RunScheduleErrorCode, type RunScheduleOptions, type ScheduleDefinition, type ScheduleDefinitionInput, type ScheduleDefinitionRegistry, type ScheduleErrorCode, type ScheduleErrorDetails, type ScheduleErrorField, type ScheduleErrorValueType, type ScheduleHandler, type ScheduleKVSetOptions, type ScheduleKVStorage, type ScheduleName, type ScheduleRegistry, type ScheduleRegistryDefinition, type ScheduleRegistryState, type ScheduleRunAttemptRecord, type ScheduleRunAttemptStatus, type ScheduleRunContext, type ScheduleRunError, type ScheduleRunListOptions, type ScheduleRunRecord, type ScheduleRunResponse, type ScheduleRunStatus, type ScheduleRunStore, type ScheduleValidationErrorCode, type StartScheduleOptions, type StartScheduleTiming, type StartableScheduleName, type StartableScheduleRegistry, type StartedSchedule, type StartedScheduleErrorCode, type StartedScheduleStore, defineSchedule };
|
package/dist/index.js
CHANGED
|
@@ -1,53 +1,3 @@
|
|
|
1
1
|
import { defineSchedule } from "./definition.js";
|
|
2
|
-
import {
|
|
3
|
-
import { r as executeManualSchedule, s as resolveManualSchedule } from "./started-errors-IG9DlT2A.js";
|
|
4
|
-
import { i as startSchedule, n as getSchedule, r as listSchedules, t as cancelSchedule } from "./started-B1Se_Iwo.js";
|
|
5
|
-
import { defineErrors } from "@vite-hub/runtime";
|
|
6
|
-
// src/run-errors.ts
|
|
7
|
-
const runScheduleErrors = /*#__PURE__*/ defineErrors({
|
|
8
|
-
docs: "https://vitehub.dev/docs/schedule/diagnostics",
|
|
9
|
-
codes: {
|
|
10
|
-
SCHEDULE_INVALID_SCHEDULED_AT: {
|
|
11
|
-
why: "`runSchedule()` got a `scheduledAt` that is not a valid date-time.",
|
|
12
|
-
fix: "Pass a valid `Date`, or an ISO 8601 date-time with `Z` or an offset, such as `2026-01-31T23:59:00Z`. Leave it out to run as of now."
|
|
13
|
-
},
|
|
14
|
-
SCHEDULE_RUN_STORE_FAILED: {
|
|
15
|
-
why: "The store of Schedule Runs failed, so the run did not start or its record is incomplete. `error.cause` has the store error.",
|
|
16
|
-
fix: "Check that the Schedule run store is reachable from this server. Before retrying, confirm that the handler did not already run or that it is safe to repeat."
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
// src/run.ts
|
|
21
|
-
const registryModule = "#vitehub/schedule/registry";
|
|
22
|
-
async function loadRegistry() {
|
|
23
|
-
try {
|
|
24
|
-
return (await import(
|
|
25
|
-
/* @vite-ignore */
|
|
26
|
-
/* @vitehub-schedule-registry */
|
|
27
|
-
registryModule
|
|
28
|
-
)).default;
|
|
29
|
-
} catch (cause) {
|
|
30
|
-
throw createScheduleError("SCHEDULE_DEFINITION_NOT_FOUND", { cause });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Runs a Static Schedule Definition that sets `manual: true` now, as if its cron fired at `scheduledAt` (default: now).
|
|
35
|
-
* It returns `[error, run]`. A failed handler is a run with `status: "failed"`, not an error. An invalid `scheduledAt`
|
|
36
|
-
* or a failed run store is `error`. Definition loading errors, unknown names, and Definitions without `manual: true` throw.
|
|
37
|
-
*/
|
|
38
|
-
async function runSchedule(name, options = {}) {
|
|
39
|
-
const registry = await loadRegistry();
|
|
40
|
-
const definition = await resolveManualSchedule(registry, name);
|
|
41
|
-
let scheduledAt;
|
|
42
|
-
try {
|
|
43
|
-
scheduledAt = parseScheduledAt(options.scheduledAt);
|
|
44
|
-
} catch (cause) {
|
|
45
|
-
return [runScheduleErrors.SCHEDULE_INVALID_SCHEDULED_AT({ cause }), void 0];
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
return [void 0, await executeManualSchedule(definition, name, scheduledAt)];
|
|
49
|
-
} catch (cause) {
|
|
50
|
-
return [runScheduleErrors.SCHEDULE_RUN_STORE_FAILED({ cause }), void 0];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
2
|
+
import { i as startSchedule, n as getSchedule, o as runSchedule, r as listSchedules, t as cancelSchedule } from "./started-ClJ5XOWH.js";
|
|
53
3
|
export { cancelSchedule, defineSchedule, getSchedule, listSchedules, runSchedule, startSchedule };
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
interface ScheduleKVSetOptions {
|
|
2
|
+
/** Seconds until the KV store deletes the value. A store that ignores it keeps the value. */
|
|
3
|
+
ttl?: number;
|
|
4
|
+
}
|
|
1
5
|
interface ScheduleKVStorage {
|
|
2
6
|
delete(key: string): boolean | Promise<boolean> | Promise<void> | void;
|
|
3
7
|
get<T = unknown>(key: string): Promise<T | null | undefined> | T | null | undefined;
|
|
4
8
|
has(key: string): boolean | Promise<boolean>;
|
|
5
9
|
keys(base?: string): Promise<string[]> | string[];
|
|
6
|
-
set<T = unknown>(key: string, value: T): Promise<void> | void;
|
|
10
|
+
set<T = unknown>(key: string, value: T, options?: ScheduleKVSetOptions): Promise<void> | void;
|
|
7
11
|
}
|
|
8
12
|
interface ViteHubKVStorage {
|
|
9
13
|
delete(key: string): Promise<readonly [unknown, unknown]>;
|
|
@@ -14,7 +18,7 @@ interface ViteHubKVStorage {
|
|
|
14
18
|
}): Promise<readonly [unknown, {
|
|
15
19
|
keys: string[];
|
|
16
20
|
} | undefined]>;
|
|
17
|
-
set<T = unknown>(key: string, value: T): Promise<readonly [unknown, unknown]>;
|
|
21
|
+
set<T = unknown>(key: string, value: T, options?: ScheduleKVSetOptions): Promise<readonly [unknown, unknown]>;
|
|
18
22
|
}
|
|
19
23
|
declare function createScheduleKVStorage(kvStore: ViteHubKVStorage): ScheduleKVStorage;
|
|
20
|
-
export {
|
|
24
|
+
export { ScheduleKVStorage as n, createScheduleKVStorage as r, ScheduleKVSetOptions as t };
|
|
@@ -20,8 +20,8 @@ function createScheduleKVStorage(kvStore) {
|
|
|
20
20
|
if (error) throw error;
|
|
21
21
|
return value?.keys ?? [];
|
|
22
22
|
},
|
|
23
|
-
async set(key, value) {
|
|
24
|
-
const [error] = await kvStore.set(key, value);
|
|
23
|
+
async set(key, value, options) {
|
|
24
|
+
const [error] = await kvStore.set(key, value, options);
|
|
25
25
|
if (error) throw error;
|
|
26
26
|
}
|
|
27
27
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as redactInspectionText } from "./inspect-CW0qwt9p.js";
|
|
2
|
-
import { t as scheduleErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
-
import {
|
|
4
|
-
import "./started-
|
|
5
|
-
import {
|
|
6
|
-
import { i as
|
|
2
|
+
import { t as scheduleErrorDiagnostics } from "./error-diagnostics-KvK9MX6w.js";
|
|
3
|
+
import { C as createScheduleError } from "./static--wi-oIIb.js";
|
|
4
|
+
import { a as loadScheduleRegistry, i as startSchedule, r as listSchedules, t as cancelSchedule } from "./started-ClJ5XOWH.js";
|
|
5
|
+
import { a as loadStaticScheduleDefinition, s as runScheduleFrom } from "./execute-DoQC2i_V.js";
|
|
6
|
+
import { i as getScheduleRunStore, n as getProcessScheduleDefinitions, o as getStartedScheduleRuntime, t as getHostScheduleInventory } from "./state-CcVY3UzB.js";
|
|
7
7
|
// src/runtime/operations.ts
|
|
8
8
|
function isoDate(value) {
|
|
9
9
|
if (value === void 0) return;
|
|
@@ -66,12 +66,12 @@ function summarizeScheduleRunAttempt(attempt) {
|
|
|
66
66
|
function newestFirst(left, right) {
|
|
67
67
|
return new Date(right.scheduledAt).getTime() - new Date(left.scheduledAt).getTime();
|
|
68
68
|
}
|
|
69
|
-
/** Lists the recorded
|
|
69
|
+
/** Lists the recorded Schedule Runs, newest first, or only the runs of `scheduleId`. */
|
|
70
70
|
async function listScheduleRuns(scheduleId, options = {}) {
|
|
71
71
|
const runs = (await getScheduleRunStore().listRuns({
|
|
72
|
-
scheduleId,
|
|
72
|
+
...scheduleId === void 0 ? {} : { scheduleId },
|
|
73
73
|
limit: options.limit
|
|
74
|
-
})).filter((run) => run.scheduleId === scheduleId).sort(newestFirst);
|
|
74
|
+
})).filter((run) => scheduleId === void 0 || run.scheduleId === scheduleId).sort(newestFirst);
|
|
75
75
|
return (options.limit === void 0 ? runs : runs.slice(0, options.limit)).map(summarizeScheduleRun);
|
|
76
76
|
}
|
|
77
77
|
/** Lists the attempts of one Schedule Run, oldest first. */
|
|
@@ -100,7 +100,10 @@ function withStatus(error, status, fix) {
|
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
-
const errorFix = {
|
|
103
|
+
const errorFix = {
|
|
104
|
+
SCHEDULE_INVALID_SCHEDULED_AT: "Pass `at` as an ISO 8601 date-time with a time zone, such as 2026-01-31T23:59:00Z or 2026-01-31T23:59:00+01:00.",
|
|
105
|
+
SCHEDULE_MANUAL_RUN_DISABLED: "Remove `manual: false` from defineSchedule() to let `vitehub schedule run`, the Console, and `runSchedule()` start the Schedule."
|
|
106
|
+
};
|
|
104
107
|
const errorStatus = {
|
|
105
108
|
SCHEDULE_DEFINITION_NOT_FOUND: 404,
|
|
106
109
|
SCHEDULE_INVALID_SCHEDULED_AT: 400,
|
|
@@ -133,12 +136,21 @@ async function runScheduleAttempts(input) {
|
|
|
133
136
|
}
|
|
134
137
|
const consoleSchedulesKey = Symbol.for("vitehub.console.schedules");
|
|
135
138
|
/**
|
|
136
|
-
* Runs a Static Schedule
|
|
137
|
-
*
|
|
139
|
+
* Runs a Static Schedule as if its cron fired at `at` (default: now) when its Definition is in the Console registry.
|
|
140
|
+
* A known Definition with `manual: false` fails with `SCHEDULE_MANUAL_RUN_DISABLED`. Other unavailable names fail with `SCHEDULE_DEFINITION_NOT_FOUND`.
|
|
138
141
|
*/
|
|
139
142
|
async function runScheduleNow(input, registry = Reflect.get(globalThis, consoleSchedulesKey) ?? {}) {
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
return await attempt(async () => {
|
|
144
|
+
if (!Object.hasOwn(registry, input.name)) {
|
|
145
|
+
const definitions = await loadScheduleRegistry().catch((cause) => {
|
|
146
|
+
throw scheduleErrorDiagnostics.SCHEDULE_DEFINITION_NOT_FOUND({ cause });
|
|
147
|
+
});
|
|
148
|
+
const definition = await loadStaticScheduleDefinition(input.name, definitions);
|
|
149
|
+
if (definition && definition.options?.manual === false) throw createScheduleError("SCHEDULE_MANUAL_RUN_DISABLED");
|
|
150
|
+
throw scheduleErrorDiagnostics.SCHEDULE_DEFINITION_NOT_FOUND();
|
|
151
|
+
}
|
|
152
|
+
return { run: summarizeManualScheduleRun(await runScheduleFrom(registry, input.name, { scheduledAt: input.at })) };
|
|
153
|
+
});
|
|
142
154
|
}
|
|
143
155
|
function summarizeStartedSchedule(schedule) {
|
|
144
156
|
return {
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as AnyOperation } from "./
|
|
2
|
-
import {
|
|
1
|
+
import { t as AnyOperation } from "./operations-Blwi3jQF.js";
|
|
2
|
+
import { p as ScheduleRunAttemptStatus, y as ScheduleRunStatus } from "./types-Wllh0U8N.js";
|
|
3
3
|
/** Error of a run or attempt. The stack is not included. */
|
|
4
4
|
interface ScheduleRunErrorSummary {
|
|
5
5
|
message: string;
|
package/dist/operations.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as isRecordOrFunction } from "./object-CAK6UYR5.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
|
import * as v from "valibot";
|
|
5
5
|
// ../internal/src/standard-schema.ts
|
|
@@ -139,18 +139,20 @@ function table(rows) {
|
|
|
139
139
|
return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" ")).join("\n");
|
|
140
140
|
}
|
|
141
141
|
// src/operations.ts
|
|
142
|
-
const runtime = () => import("./operations-
|
|
142
|
+
const runtime = () => import("./operations-CEZCefAG.js");
|
|
143
143
|
const id = v.pipe(v.string(), v.minLength(1));
|
|
144
144
|
function formatRuns({ runs }) {
|
|
145
145
|
if (runs.length === 0) return "No runs.\n";
|
|
146
146
|
return `${table([[
|
|
147
147
|
"RUN",
|
|
148
|
+
"SCHEDULE",
|
|
148
149
|
"STATUS",
|
|
149
150
|
"SCHEDULED AT",
|
|
150
151
|
"ATTEMPTS",
|
|
151
152
|
"ERROR"
|
|
152
153
|
], ...runs.map((run) => [
|
|
153
154
|
run.id,
|
|
155
|
+
run.scheduleId,
|
|
154
156
|
run.status,
|
|
155
157
|
run.scheduledAt,
|
|
156
158
|
String(run.attemptCount),
|
|
@@ -195,9 +197,9 @@ const runs = defineScheduleOperation({
|
|
|
195
197
|
namespace: "schedule",
|
|
196
198
|
positional: ["id"]
|
|
197
199
|
},
|
|
198
|
-
description: "List the recorded
|
|
200
|
+
description: "List the recorded Schedule Runs, newest first. Pass `id`, a Schedule Definition name or a started Schedule id, to list the runs of one Schedule.",
|
|
199
201
|
input: v.object({
|
|
200
|
-
id,
|
|
202
|
+
id: v.optional(id),
|
|
201
203
|
limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(100)))
|
|
202
204
|
}),
|
|
203
205
|
kind: "read",
|
|
@@ -224,7 +226,7 @@ const run = defineScheduleOperation({
|
|
|
224
226
|
namespace: "schedule",
|
|
225
227
|
positional: ["name"]
|
|
226
228
|
},
|
|
227
|
-
description: "Run a Static Schedule Definition now
|
|
229
|
+
description: "Run a Static Schedule Definition now, unless it sets `manual: false`. `at` runs it as if the cron fired at that ISO 8601 date-time.",
|
|
228
230
|
input: v.object({
|
|
229
231
|
at: v.optional(v.string()),
|
|
230
232
|
name: id
|
package/dist/os.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
2
2
|
import { t as isIanaTimeZone } from "./time-zone-pMp_g8Uu.js";
|
|
3
|
-
import { a as parseCronFields, c as timesOfDay, i as isWeekdayRestricted, n as isDayRestricted, o as range, r as isMonthRestricted, s as runsEveryDay, t as arithmeticStep, u as invariantError } from "./cron-
|
|
4
|
-
import { i as timeZoneOffsetMinutes } from "./due-
|
|
3
|
+
import { a as parseCronFields, c as timesOfDay, i as isWeekdayRestricted, n as isDayRestricted, o as range, r as isMonthRestricted, s as runsEveryDay, t as arithmeticStep, u as invariantError } from "./cron-imqlBgO-.js";
|
|
4
|
+
import { i as timeZoneOffsetMinutes } from "./due-DXgXKgzg.js";
|
|
5
5
|
import { defineErrors } from "@vite-hub/runtime";
|
|
6
6
|
import { homedir, userInfo } from "node:os";
|
|
7
7
|
import { basename, dirname, join, posix, win32 } from "node:path";
|