@vite-hub/schedule 0.6.1 → 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/dist/runtime/console.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { n as getProcessScheduleDefinitions, o as getStartedScheduleRuntime } from "../state-
|
|
1
|
+
import { n as getProcessScheduleDefinitions, o as getStartedScheduleRuntime } from "../state-CcVY3UzB.js";
|
|
2
|
+
import { o as resolveManualSchedule } from "../execute-DoQC2i_V.js";
|
|
2
3
|
// src/runtime/console.ts
|
|
4
|
+
const consoleSchedulesKey = Symbol.for("vitehub.console.schedules");
|
|
3
5
|
/** The Cron column of the Console: the cron, with the time zone when it is not UTC. */
|
|
4
6
|
function scheduleConsoleTiming(cron, timeZone) {
|
|
5
7
|
return timeZone === "UTC" ? cron : `${cron} (${timeZone})`;
|
|
@@ -59,23 +61,34 @@ function startedScheduleRecord(schedule) {
|
|
|
59
61
|
* build checked.
|
|
60
62
|
*/
|
|
61
63
|
async function readScheduleConsoleRecords() {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const registry = Reflect.get(globalThis, consoleSchedulesKey) ?? {};
|
|
65
|
+
const definitions = getProcessScheduleDefinitions();
|
|
66
|
+
const candidates = await Promise.all(Object.keys(registry).map((name) => resolveManualSchedule(registry, name).then(() => name, () => void 0)));
|
|
67
|
+
const runnable = new Set(candidates.filter((name) => name !== void 0));
|
|
68
|
+
const records = [.../* @__PURE__ */ new Set([...definitions?.keys() ?? [], ...runnable])].map((name) => {
|
|
69
|
+
const definition = definitions?.get(name);
|
|
70
|
+
const timeZone = definition?.timeZone ?? "UTC";
|
|
71
|
+
const cron = definition?.cron;
|
|
72
|
+
const canRun = runnable.has(name);
|
|
73
|
+
return {
|
|
66
74
|
cells: {
|
|
75
|
+
...canRun ? { manual: "Enabled" } : {},
|
|
67
76
|
schedule: name,
|
|
68
|
-
timing: scheduleConsoleTiming(
|
|
77
|
+
...cron === void 0 ? {} : { timing: scheduleConsoleTiming(cron, timeZone) }
|
|
69
78
|
},
|
|
70
|
-
fields: [{
|
|
79
|
+
fields: [...cron === void 0 ? [] : [{
|
|
71
80
|
label: "Cron",
|
|
72
|
-
value:
|
|
81
|
+
value: cron
|
|
73
82
|
}, {
|
|
74
83
|
label: "Time zone",
|
|
75
84
|
value: timeZone
|
|
76
|
-
}],
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
}], ...canRun ? [{
|
|
86
|
+
label: "Manual",
|
|
87
|
+
value: "Enabled"
|
|
88
|
+
}] : []],
|
|
89
|
+
id: `definition:${name}`,
|
|
90
|
+
...canRun ? { runnable: true } : {}
|
|
91
|
+
};
|
|
79
92
|
});
|
|
80
93
|
const started = getStartedScheduleRuntime();
|
|
81
94
|
if (!started) return records;
|
package/dist/runtime/kv.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as ScheduleKVStorage } from "../kv-storage-CKSSQ6Fk.js";
|
|
2
2
|
export declare const scheduleKVStorage: ScheduleKVStorage;
|
package/dist/runtime/kv.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createScheduleKVStorage } from "../kv-storage-
|
|
1
|
+
import { t as createScheduleKVStorage } from "../kv-storage-CszEkof6.js";
|
|
2
2
|
import * as kvPackage from "@vite-hub/kv";
|
|
3
3
|
// src/runtime/kv.ts
|
|
4
4
|
const scheduleKVStorage = createScheduleKVStorage(kvPackage.kv);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as ScheduleRunStore, o as ScheduleDefinitionRegistry } from "../types-Wllh0U8N.js";
|
|
2
2
|
import { LeaseStore } from "@vite-hub/runtime";
|
|
3
3
|
import { onShutdown } from "@vite-hub/runtime/internal/shutdown";
|
|
4
4
|
export interface ProcessScheduleRuntimeOptions {
|
package/dist/runtime/process.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { n as isRecordOrFunction } from "../object-CAK6UYR5.js";
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { i as
|
|
7
|
-
import {
|
|
2
|
+
import { n as parseScheduleCronExpression } from "../cron-D0mqg3ql.js";
|
|
3
|
+
import { n as isScheduleDue } from "../due-DXgXKgzg.js";
|
|
4
|
+
import { t as scheduleErrorDiagnostics } from "../error-diagnostics-KvK9MX6w.js";
|
|
5
|
+
import { C as createScheduleError, c as markLoggedScheduleError, x as scheduleIdempotencyKey } from "../static--wi-oIIb.js";
|
|
6
|
+
import { c as toRunId, i as executeStaticSchedule } from "../execute-DoQC2i_V.js";
|
|
7
|
+
import { i as runStartedSchedules } from "../started-yb49f37g.js";
|
|
8
|
+
import { a as getScheduleRuntimeRegistry, c as registerProcessScheduleDefinitions, d as setScheduleOccurrenceClaims, f as setScheduleRunStore, i as getScheduleRunStore, p as setScheduleRuntimeRegistry, r as getScheduleOccurrenceClaims } from "../state-CcVY3UzB.js";
|
|
8
9
|
import { createMemoryLeaseStore, getInstanceId } from "@vite-hub/runtime";
|
|
9
10
|
import { onShutdown } from "@vite-hub/runtime/internal/shutdown";
|
|
10
11
|
// src/internal/process-wake-runtime.ts
|
|
@@ -316,6 +317,7 @@ async function loadStaticDefinitions(registry, timings = {}) {
|
|
|
316
317
|
};
|
|
317
318
|
const definition = unwrapDefinition(await load());
|
|
318
319
|
if (!definition) return void 0;
|
|
320
|
+
parseScheduleCronExpression(definition.cron, `Schedule "${name}"`);
|
|
319
321
|
return {
|
|
320
322
|
cron: definition.cron,
|
|
321
323
|
definition: async () => definition,
|
|
@@ -452,16 +454,12 @@ async function installProcessScheduleRuntime(options) {
|
|
|
452
454
|
const currentMinute = Math.floor((options.now?.() ?? /* @__PURE__ */ new Date()).getTime() / minuteMs) * minuteMs;
|
|
453
455
|
const since = currentMinute - catchUpMs;
|
|
454
456
|
for (const entry of definitions.values()) try {
|
|
455
|
-
|
|
456
|
-
for (let minute =
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
scheduleId: entry.name
|
|
462
|
-
});
|
|
463
|
-
for (const run of runs) {
|
|
464
|
-
if (run.scheduledAt.getTime() < since) continue;
|
|
457
|
+
const cron = scheduleCronRecord(entry);
|
|
458
|
+
for (let minute = currentMinute - minuteMs; minute >= since; minute -= minuteMs) {
|
|
459
|
+
const scheduledAt = new Date(minute);
|
|
460
|
+
if (!isScheduleDue(cron, scheduledAt)) continue;
|
|
461
|
+
const run = await options.scheduleRunStore.getRun(toRunId("static", entry.name, scheduledAt));
|
|
462
|
+
if (!run) continue;
|
|
465
463
|
if (run.status !== "pending" && run.status !== "running") continue;
|
|
466
464
|
held.set(run.id, {
|
|
467
465
|
scheduleId: entry.name,
|
package/dist/runtime/state.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as getScheduleRunStore, c as loadScheduleDefinition, d as setHostScheduleInventory, f as setScheduleOccurrenceClaims, h as setStartedScheduleRuntime, i as getScheduleOccurrenceClaims, l as registerProcessScheduleDefinitions, m as setScheduleRuntimeRegistry, n as getHostScheduleInventory, o as getScheduleRuntimeRegistry, p as setScheduleRunStore, r as getProcessScheduleDefinitions, s as getStartedScheduleRuntime, t as StartedScheduleRuntime, u as resetScheduleRuntime } from "../state-
|
|
1
|
+
import { a as getScheduleRunStore, c as loadScheduleDefinition, d as setHostScheduleInventory, f as setScheduleOccurrenceClaims, h as setStartedScheduleRuntime, i as getScheduleOccurrenceClaims, l as registerProcessScheduleDefinitions, m as setScheduleRuntimeRegistry, n as getHostScheduleInventory, o as getScheduleRuntimeRegistry, p as setScheduleRunStore, r as getProcessScheduleDefinitions, s as getStartedScheduleRuntime, t as StartedScheduleRuntime, u as resetScheduleRuntime } from "../state-LuEgYpwR.js";
|
|
2
2
|
export { StartedScheduleRuntime, getHostScheduleInventory, getProcessScheduleDefinitions, getScheduleOccurrenceClaims, getScheduleRunStore, getScheduleRuntimeRegistry, getStartedScheduleRuntime, loadScheduleDefinition, registerProcessScheduleDefinitions, resetScheduleRuntime, setHostScheduleInventory, setScheduleOccurrenceClaims, setScheduleRunStore, setScheduleRuntimeRegistry, setStartedScheduleRuntime };
|
package/dist/runtime/state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as getHostScheduleInventory, n as getProcessScheduleDefinitions, r as getScheduleOccurrenceClaims, i as getScheduleRunStore, a as getScheduleRuntimeRegistry, o as getStartedScheduleRuntime, s as loadScheduleDefinition, c as registerProcessScheduleDefinitions, l as resetScheduleRuntime, u as setHostScheduleInventory, d as setScheduleOccurrenceClaims, f as setScheduleRunStore, p as setScheduleRuntimeRegistry, m as setStartedScheduleRuntime } from "../state-
|
|
1
|
+
export { t as getHostScheduleInventory, n as getProcessScheduleDefinitions, r as getScheduleOccurrenceClaims, i as getScheduleRunStore, a as getScheduleRuntimeRegistry, o as getStartedScheduleRuntime, s as loadScheduleDefinition, c as registerProcessScheduleDefinitions, l as resetScheduleRuntime, u as setHostScheduleInventory, d as setScheduleOccurrenceClaims, f as setScheduleRunStore, p as setScheduleRuntimeRegistry, m as setStartedScheduleRuntime } from "../state-CcVY3UzB.js";
|
package/dist/runtime/static.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as unwrapScheduleDefinition, a as createStaticScheduleRun, c as executeStaticSchedule, d as logScheduleRuntimeError, f as markLoggedScheduleError, g as scheduledWakeTime, h as normalizeScheduleRuntimeError, i as StaticScheduleRun, l as isScheduleCronAuthorized, m as normalizeCron, n as ExecuteMatchingStaticSchedulesOptions, o as executeCloudflareStaticSchedules, p as missingScheduleDefinitionError, r as ExecuteStaticScheduleOptions, s as executeMatchingStaticSchedules, t as ExecuteCloudflareStaticSchedulesOptions, u as isTimeZoneWakeDue, v as cronWithWeekdayNames } from "../static-
|
|
1
|
+
import { _ as unwrapScheduleDefinition, a as createStaticScheduleRun, c as executeStaticSchedule, d as logScheduleRuntimeError, f as markLoggedScheduleError, g as scheduledWakeTime, h as normalizeScheduleRuntimeError, i as StaticScheduleRun, l as isScheduleCronAuthorized, m as normalizeCron, n as ExecuteMatchingStaticSchedulesOptions, o as executeCloudflareStaticSchedules, p as missingScheduleDefinitionError, r as ExecuteStaticScheduleOptions, s as executeMatchingStaticSchedules, t as ExecuteCloudflareStaticSchedulesOptions, u as isTimeZoneWakeDue, v as cronWithWeekdayNames } from "../static-BFV4x94g.js";
|
|
2
2
|
export { ExecuteCloudflareStaticSchedulesOptions, ExecuteMatchingStaticSchedulesOptions, ExecuteStaticScheduleOptions, StaticScheduleRun, createStaticScheduleRun, cronWithWeekdayNames, executeCloudflareStaticSchedules, executeMatchingStaticSchedules, executeStaticSchedule, isScheduleCronAuthorized, isTimeZoneWakeDue, logScheduleRuntimeError, markLoggedScheduleError, missingScheduleDefinitionError, normalizeCron, normalizeScheduleRuntimeError, scheduledWakeTime, unwrapScheduleDefinition };
|
package/dist/runtime/static.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as isScheduleCronAuthorized, c as markLoggedScheduleError, d as normalizeScheduleRuntimeError, f as scheduledWakeTime, i as executeStaticSchedule, l as missingScheduleDefinitionError, n as executeCloudflareStaticSchedules, o as isTimeZoneWakeDue, p as unwrapScheduleDefinition, r as executeMatchingStaticSchedules, s as logScheduleRuntimeError, t as createStaticScheduleRun, u as normalizeCron } from "../static-
|
|
2
|
-
import { t as cronWithWeekdayNames } from "../due-
|
|
1
|
+
import { a as isScheduleCronAuthorized, c as markLoggedScheduleError, d as normalizeScheduleRuntimeError, f as scheduledWakeTime, i as executeStaticSchedule, l as missingScheduleDefinitionError, n as executeCloudflareStaticSchedules, o as isTimeZoneWakeDue, p as unwrapScheduleDefinition, r as executeMatchingStaticSchedules, s as logScheduleRuntimeError, t as createStaticScheduleRun, u as normalizeCron } from "../static--wi-oIIb.js";
|
|
2
|
+
import { t as cronWithWeekdayNames } from "../due-DXgXKgzg.js";
|
|
3
3
|
export { createStaticScheduleRun, cronWithWeekdayNames, executeCloudflareStaticSchedules, executeMatchingStaticSchedules, executeStaticSchedule, isScheduleCronAuthorized, isTimeZoneWakeDue, logScheduleRuntimeError, markLoggedScheduleError, missingScheduleDefinitionError, normalizeCron, normalizeScheduleRuntimeError, scheduledWakeTime, unwrapScheduleDefinition };
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference path="./registry-module.d.ts" />
|
|
2
|
-
import { a as createScheduleRun, c as runScheduleFrom, n as createKVScheduleRunStore, o as executeSchedule, r as createMemoryScheduleRunStore, s as executeStaticSchedule, t as KVScheduleStoreOptions } from "./store-
|
|
3
|
-
import { _ as unwrapScheduleDefinition, m as normalizeCron } from "./static-
|
|
4
|
-
import { n as createScheduleKVStorage, t as
|
|
5
|
-
import {
|
|
6
|
-
import { a as getScheduleRunStore, p as setScheduleRunStore, u as resetScheduleRuntime } from "./state-
|
|
2
|
+
import { a as createScheduleRun, c as runScheduleFrom, n as createKVScheduleRunStore, o as executeSchedule, r as createMemoryScheduleRunStore, s as executeStaticSchedule, t as KVScheduleStoreOptions } from "./store-TOayO0NL.js";
|
|
3
|
+
import { _ as unwrapScheduleDefinition, m as normalizeCron } from "./static-BFV4x94g.js";
|
|
4
|
+
import { n as ScheduleKVStorage, r as createScheduleKVStorage, t as ScheduleKVSetOptions } from "./kv-storage-CKSSQ6Fk.js";
|
|
5
|
+
import { E as StartedScheduleStore, _ as ScheduleRunRecord, a as ScheduleDefinitionOptions, b as ScheduleRunStore, f as ScheduleRunAttemptRecord, g as ScheduleRunListOptions, m as ScheduleRunContext, o as ScheduleDefinitionRegistry, r as ScheduleDefinition, s as ScheduleHandler, u as ScheduleRegistryDefinition } from "./types-Wllh0U8N.js";
|
|
6
|
+
import { a as getScheduleRunStore, p as setScheduleRunStore, u as resetScheduleRuntime } from "./state-LuEgYpwR.js";
|
|
7
7
|
interface InstallStartedSchedulesOptions {
|
|
8
8
|
/**
|
|
9
9
|
* How far back, in milliseconds, the first tick after a start runs cron minutes that no tick checked. Use it only with
|
|
@@ -34,4 +34,4 @@ export declare function createKVStartedScheduleStore(options: KVStartedScheduleS
|
|
|
34
34
|
* that started Schedule and logged; it does not fail the tick.
|
|
35
35
|
*/
|
|
36
36
|
export declare function runStartedSchedules(context: ScheduleRunContext): Promise<void>;
|
|
37
|
-
export { type InstallStartedSchedulesOptions, type KVScheduleStoreOptions, type KVStartedScheduleStoreOptions, type ScheduleDefinition, type ScheduleDefinitionOptions, type ScheduleDefinitionRegistry, type ScheduleHandler, type ScheduleKVStorage, type ScheduleRegistryDefinition, type ScheduleRunAttemptRecord, type ScheduleRunContext, type ScheduleRunListOptions, type ScheduleRunRecord, type ScheduleRunStore, createKVScheduleRunStore, createMemoryScheduleRunStore, createScheduleKVStorage, createScheduleRun, executeSchedule, executeStaticSchedule, getScheduleRunStore, normalizeCron, resetScheduleRuntime, runScheduleFrom, setScheduleRunStore, unwrapScheduleDefinition };
|
|
37
|
+
export { type InstallStartedSchedulesOptions, type KVScheduleStoreOptions, type KVStartedScheduleStoreOptions, type ScheduleDefinition, type ScheduleDefinitionOptions, type ScheduleDefinitionRegistry, type ScheduleHandler, type ScheduleKVSetOptions, type ScheduleKVStorage, type ScheduleRegistryDefinition, type ScheduleRunAttemptRecord, type ScheduleRunContext, type ScheduleRunListOptions, type ScheduleRunRecord, type ScheduleRunStore, createKVScheduleRunStore, createMemoryScheduleRunStore, createScheduleKVStorage, createScheduleRun, executeSchedule, executeStaticSchedule, getScheduleRunStore, normalizeCron, resetScheduleRuntime, runScheduleFrom, setScheduleRunStore, unwrapScheduleDefinition };
|
package/dist/runtime.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { p as unwrapScheduleDefinition, u as normalizeCron } from "./static-
|
|
3
|
-
import { t as createScheduleKVStorage } from "./kv-storage-
|
|
4
|
-
import {
|
|
5
|
-
import { i as runStartedSchedules, n as createMemoryStartedScheduleStore, r as installStartedSchedules, t as createKVStartedScheduleStore } from "./started-
|
|
1
|
+
import { i as executeStaticSchedule, r as executeSchedule, s as runScheduleFrom, t as createScheduleRun } from "./execute-DoQC2i_V.js";
|
|
2
|
+
import { p as unwrapScheduleDefinition, u as normalizeCron } from "./static--wi-oIIb.js";
|
|
3
|
+
import { t as createScheduleKVStorage } from "./kv-storage-CszEkof6.js";
|
|
4
|
+
import { _ as createMemoryScheduleRunStore, f as setScheduleRunStore, g as createKVScheduleRunStore, i as getScheduleRunStore, l as resetScheduleRuntime } from "./state-CcVY3UzB.js";
|
|
5
|
+
import { i as runStartedSchedules, n as createMemoryStartedScheduleStore, r as installStartedSchedules, t as createKVStartedScheduleStore } from "./started-yb49f37g.js";
|
|
6
6
|
export { createKVScheduleRunStore, createKVStartedScheduleStore, createMemoryScheduleRunStore, createMemoryStartedScheduleStore, createScheduleKVStorage, createScheduleRun, executeSchedule, executeStaticSchedule, getScheduleRunStore, installStartedSchedules, normalizeCron, resetScheduleRuntime, runScheduleFrom, runStartedSchedules, setScheduleRunStore, unwrapScheduleDefinition };
|
|
@@ -1,9 +1,53 @@
|
|
|
1
|
-
import { t as startedScheduleErrors, u as randomId } from "./started-errors-IG9DlT2A.js";
|
|
2
1
|
import { t as isIanaTimeZone } from "./time-zone-pMp_g8Uu.js";
|
|
3
2
|
import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
|
|
4
|
-
import {
|
|
5
|
-
import { o as
|
|
3
|
+
import { C as createScheduleError, b as parseScheduledAt } from "./static--wi-oIIb.js";
|
|
4
|
+
import { l as randomId, n as executeManualSchedule, o as resolveManualSchedule } from "./execute-DoQC2i_V.js";
|
|
5
|
+
import { o as getStartedScheduleRuntime } from "./state-CcVY3UzB.js";
|
|
6
|
+
import { t as startedScheduleErrors } from "./started-errors-DVw5cYHR.js";
|
|
6
7
|
import { parseCronExpression } from "cron-schedule";
|
|
8
|
+
import { defineErrors } from "@vite-hub/runtime";
|
|
9
|
+
// src/run-errors.ts
|
|
10
|
+
const runScheduleErrors = /*#__PURE__*/ defineErrors({
|
|
11
|
+
docs: "https://vitehub.dev/docs/schedule/diagnostics",
|
|
12
|
+
codes: {
|
|
13
|
+
SCHEDULE_INVALID_SCHEDULED_AT: {
|
|
14
|
+
why: "`runSchedule()` got a `scheduledAt` that is not a valid date-time.",
|
|
15
|
+
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."
|
|
16
|
+
},
|
|
17
|
+
SCHEDULE_RUN_STORE_FAILED: {
|
|
18
|
+
why: "The store of Schedule Runs failed, so the run did not start or its record is incomplete. `error.cause` has the store error.",
|
|
19
|
+
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."
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
// src/run.ts
|
|
24
|
+
const registryModule = "#vitehub/schedule/registry";
|
|
25
|
+
async function loadScheduleRegistry() {
|
|
26
|
+
try {
|
|
27
|
+
return (await import(
|
|
28
|
+
/* @vite-ignore */
|
|
29
|
+
/* @vitehub-schedule-registry */
|
|
30
|
+
registryModule
|
|
31
|
+
)).default;
|
|
32
|
+
} catch (cause) {
|
|
33
|
+
throw createScheduleError("SCHEDULE_DEFINITION_NOT_FOUND", { cause });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function runSchedule(name, options = {}) {
|
|
37
|
+
const registry = await loadScheduleRegistry();
|
|
38
|
+
const definition = await resolveManualSchedule(registry, name);
|
|
39
|
+
let scheduledAt;
|
|
40
|
+
try {
|
|
41
|
+
scheduledAt = parseScheduledAt(options.scheduledAt);
|
|
42
|
+
} catch (cause) {
|
|
43
|
+
return [runScheduleErrors.SCHEDULE_INVALID_SCHEDULED_AT({ cause }), void 0];
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
return [void 0, await executeManualSchedule(definition, name, scheduledAt)];
|
|
47
|
+
} catch (cause) {
|
|
48
|
+
return [runScheduleErrors.SCHEDULE_RUN_STORE_FAILED({ cause }), void 0];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
7
51
|
// src/started.ts
|
|
8
52
|
const optionKeys = /* @__PURE__ */ new Set([
|
|
9
53
|
"at",
|
|
@@ -101,11 +145,6 @@ async function fromStore(work) {
|
|
|
101
145
|
return [startedScheduleErrors.SCHEDULE_STORE_FAILED({ cause }), void 0];
|
|
102
146
|
}
|
|
103
147
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Starts the Schedule Definition `name`, which declares no `cron`, at a time that code picks: once at `at`, or on each
|
|
106
|
-
* occurrence of `cron` in `timeZone` until `cancelSchedule()`. The store keeps it across restarts and deploys. The handler
|
|
107
|
-
* receives `payload` as `context.payload`.
|
|
108
|
-
*/
|
|
109
148
|
async function startSchedule(name, options) {
|
|
110
149
|
const [missing, runtime] = requireRuntime();
|
|
111
150
|
if (missing) return [missing, void 0];
|
|
@@ -141,4 +180,4 @@ async function cancelSchedule(id) {
|
|
|
141
180
|
if (storeError) return [storeError, void 0];
|
|
142
181
|
return deleted ? [void 0, schedule] : [startedScheduleErrors.SCHEDULE_NOT_FOUND({ id: String(id) }), void 0];
|
|
143
182
|
}
|
|
144
|
-
export { startSchedule as i, getSchedule as n, listSchedules as r, cancelSchedule as t };
|
|
183
|
+
export { loadScheduleRegistry as a, startSchedule as i, getSchedule as n, runSchedule as o, listSchedules as r, cancelSchedule as t };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineErrors } from "@vite-hub/runtime";
|
|
2
|
+
// src/started-errors.ts
|
|
3
|
+
const startedScheduleErrors = /*#__PURE__*/ defineErrors({
|
|
4
|
+
docs: "https://vitehub.dev/docs/schedule/diagnostics",
|
|
5
|
+
codes: {
|
|
6
|
+
SCHEDULE_NOT_STARTABLE: {
|
|
7
|
+
why: ({ name }) => `No Schedule Definition without \`cron\` is named "${name}", so \`startSchedule()\` cannot start it.`,
|
|
8
|
+
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."
|
|
9
|
+
},
|
|
10
|
+
SCHEDULE_INVALID_OPTIONS: {
|
|
11
|
+
why: ({ problem }) => `\`startSchedule()\` options are invalid: ${problem}`,
|
|
12
|
+
fix: "Pass `{ at }` for one run, or `{ cron, timeZone }` for a repeating Schedule, and a JSON `payload`."
|
|
13
|
+
},
|
|
14
|
+
SCHEDULE_NOT_FOUND: {
|
|
15
|
+
why: ({ id }) => `No started Schedule has the id "${id}". It ran its last time, was cancelled, or never existed.`,
|
|
16
|
+
fix: "List the started Schedules with `listSchedules()` or `vitehub schedule list`."
|
|
17
|
+
},
|
|
18
|
+
SCHEDULE_STORE_MISSING: {
|
|
19
|
+
why: "This server has no store for started Schedules.",
|
|
20
|
+
fix: "Add a Schedule Definition without `cron` in `server/schedules/`, enable `kv`, and build with Nitro. On Node, also set `schedule: { runtime: { driver: \"process\" } }`."
|
|
21
|
+
},
|
|
22
|
+
SCHEDULE_STORE_FAILED: {
|
|
23
|
+
why: "The store of started Schedules failed. `error.cause` has the store error.",
|
|
24
|
+
fix: "Check that KV is enabled and reachable from this server, then try again."
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
export { startedScheduleErrors as t };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { n as isScheduleDue } from "./due-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { n as isScheduleDue } from "./due-DXgXKgzg.js";
|
|
2
|
+
import { c as toRunId, r as executeSchedule } from "./execute-DoQC2i_V.js";
|
|
3
|
+
import { m as setStartedScheduleRuntime, o as getStartedScheduleRuntime, r as getScheduleOccurrenceClaims, v as joinKey, y as keySegments } from "./state-CcVY3UzB.js";
|
|
4
|
+
import { t as startedScheduleErrors } from "./started-errors-DVw5cYHR.js";
|
|
4
5
|
import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
|
|
5
|
-
import {
|
|
6
|
+
import { v as errorCode, y as logFailure } from "./static--wi-oIIb.js";
|
|
6
7
|
import { normalizeRuntimeDiagnosticError } from "@vite-hub/runtime";
|
|
7
8
|
// src/runtime/started.ts
|
|
8
9
|
const minuteMs = 6e4;
|
|
@@ -131,6 +132,7 @@ async function runOccurrence(runtime, schedule, scheduledAt, waitUntil) {
|
|
|
131
132
|
...context,
|
|
132
133
|
payload: schedule.payload
|
|
133
134
|
}) },
|
|
135
|
+
oneShot: schedule.at !== void 0,
|
|
134
136
|
onExecution() {
|
|
135
137
|
final = true;
|
|
136
138
|
markFinal?.();
|