@vite-hub/schedule 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -7
- package/dist/{console-wEhr0LWn.d.ts → console-DFI1QBkP.d.ts} +2 -4
- package/dist/cron-BT3ef48f.js +68 -0
- package/dist/definition.d.ts +2 -4
- package/dist/definition.js +4 -6
- package/dist/{due-sOJvF_6Z.js → due-D-0trD1g.js} +23 -9
- package/dist/durability.d.ts +3 -5
- package/dist/durability.js +6 -7
- package/dist/{error-diagnostics-BBtYYl8j.js → error-diagnostics-B1AaIGWP.js} +2 -7
- package/dist/{error-diagnostics-CQ4BUqRe.js → error-diagnostics-kKXseq8d.js} +10 -3
- package/dist/index.d.ts +3 -13
- package/dist/index.js +5 -8
- package/dist/{started-name-ruCM1EtQ.js → inspect-CW0qwt9p.js} +3 -9
- package/dist/{kv-storage-2kZtP2CC.js → kv-storage-Dsr3TL9c.js} +1 -2
- package/dist/{kv-storage-Bm9aYLfZ.d.ts → kv-storage-hI2IOjb5.d.ts} +0 -2
- package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
- package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CqZkx1Rm.d.ts} +8 -6
- package/dist/{operations-DqwmJ8MN.js → operations-BTUQeba1.js} +7 -11
- package/dist/operations.d.ts +2 -6
- package/dist/operations.js +11 -16
- package/dist/os.d.ts +0 -9
- package/dist/os.js +23 -104
- package/dist/out-By90R-Bo.js +22706 -0
- package/dist/rolldown-runtime-DegdyBIC.js +25 -0
- package/dist/runtime/console.d.ts +2 -4
- package/dist/runtime/console.js +3 -4
- package/dist/runtime/kv.d.ts +2 -4
- package/dist/runtime/kv.js +2 -3
- package/dist/runtime/process.d.ts +1 -3
- package/dist/runtime/process.js +28 -52
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/state.js +1 -2
- package/dist/runtime/static.d.ts +2 -73
- package/dist/runtime/static.js +3 -2
- package/dist/runtime.d.ts +5 -7
- package/dist/runtime.js +5 -5
- package/dist/{started-B0pc3JY0.js → started-B1Se_Iwo.js} +6 -8
- package/dist/{started-Bk2Icknk.js → started-Bzvr4t5f.js} +26 -9
- package/dist/{started-errors-DEmYH-vp.js → started-errors-IG9DlT2A.js} +49 -12
- package/dist/started-name-w6n9uDdt.js +4 -0
- package/dist/{state-CPd10SXq.d.ts → state-BDEDVlyr.d.ts} +3 -6
- package/dist/{state-D4SZH6zk.js → state-BZLy46UJ.js} +73 -122
- package/dist/static-Bg7Jj92L.js +603 -0
- package/dist/static-DeRvJqcQ.d.ts +92 -0
- package/dist/{store-DeMojnXM.d.ts → store-CEv3cScg.d.ts} +4 -12
- package/dist/{time-zone-SBldrUgt.js → time-zone-pMp_g8Uu.js} +1 -2
- package/dist/{types-Cw5LjPuc.d.ts → types-DTVPVY5O.d.ts} +0 -2
- package/dist/vite.d.ts +6 -20
- package/dist/vite.js +2943 -297
- package/package.json +9 -9
- package/dist/invariant-DolT9EEx.js +0 -22
- package/dist/static-7JCga3Iu.js +0 -281
- package/dist/wait-until-Dy4Bn3ZN.js +0 -112
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
21
|
+
value: mod,
|
|
22
|
+
enumerable: true
|
|
23
|
+
}) : target, mod));
|
|
24
|
+
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
25
|
+
export { __require as n, __toESM as r, __commonJSMin as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as ViteHubConsoleRecord } from "../console-
|
|
2
|
-
//#region src/runtime/console.d.ts
|
|
1
|
+
import { t as ViteHubConsoleRecord } from "../console-DFI1QBkP.js";
|
|
3
2
|
/** The Cron column of the Console: the cron, with the time zone when it is not UTC. */
|
|
4
3
|
export declare function scheduleConsoleTiming(cron: string, timeZone: string): string;
|
|
5
4
|
/**
|
|
@@ -8,5 +7,4 @@ export declare function scheduleConsoleTiming(cron: string, timeZone: string): s
|
|
|
8
7
|
* build-time record of its Schedule. Without a Process Runtime, provider cron output uses the static UTC cron that the
|
|
9
8
|
* build checked.
|
|
10
9
|
*/
|
|
11
|
-
export declare function readScheduleConsoleRecords(): Promise<ViteHubConsoleRecord[]>;
|
|
12
|
-
//#endregion
|
|
10
|
+
export declare function readScheduleConsoleRecords(): Promise<ViteHubConsoleRecord[]>;
|
package/dist/runtime/console.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as getProcessScheduleDefinitions, o as getStartedScheduleRuntime } from "../state-
|
|
2
|
-
|
|
1
|
+
import { n as getProcessScheduleDefinitions, o as getStartedScheduleRuntime } from "../state-BZLy46UJ.js";
|
|
2
|
+
// src/runtime/console.ts
|
|
3
3
|
/** The Cron column of the Console: the cron, with the time zone when it is not UTC. */
|
|
4
4
|
function scheduleConsoleTiming(cron, timeZone) {
|
|
5
5
|
return timeZone === "UTC" ? cron : `${cron} (${timeZone})`;
|
|
@@ -46,7 +46,7 @@ function startedScheduleRecord(schedule) {
|
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
label: "Runs",
|
|
49
|
-
value: `Use \`vitehub schedule runs ${schedule.id}\` to list its runs, and \`vitehub schedule cancel ${schedule.id}\` to stop it.`
|
|
49
|
+
value: `Use \`vitehub schedule runs list ${schedule.id}\` to list its runs, and \`vitehub schedule cancel ${schedule.id}\` to stop it.`
|
|
50
50
|
}
|
|
51
51
|
],
|
|
52
52
|
id: `started:${schedule.id}`
|
|
@@ -81,5 +81,4 @@ async function readScheduleConsoleRecords() {
|
|
|
81
81
|
if (!started) return records;
|
|
82
82
|
return [...records, ...(await started.store.list()).map(startedScheduleRecord)];
|
|
83
83
|
}
|
|
84
|
-
//#endregion
|
|
85
84
|
export { readScheduleConsoleRecords, scheduleConsoleTiming };
|
package/dist/runtime/kv.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
import { t as ScheduleKVStorage } from "../kv-storage-
|
|
2
|
-
|
|
3
|
-
export declare const scheduleKVStorage: ScheduleKVStorage;
|
|
4
|
-
//#endregion
|
|
1
|
+
import { t as ScheduleKVStorage } from "../kv-storage-hI2IOjb5.js";
|
|
2
|
+
export declare const scheduleKVStorage: ScheduleKVStorage;
|
package/dist/runtime/kv.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { t as createScheduleKVStorage } from "../kv-storage-
|
|
1
|
+
import { t as createScheduleKVStorage } from "../kv-storage-Dsr3TL9c.js";
|
|
2
2
|
import * as kvPackage from "@vite-hub/kv";
|
|
3
|
-
|
|
3
|
+
// src/runtime/kv.ts
|
|
4
4
|
const scheduleKVStorage = createScheduleKVStorage(kvPackage.kv);
|
|
5
|
-
//#endregion
|
|
6
5
|
export { scheduleKVStorage };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { a as ScheduleDefinitionRegistry, g as ScheduleRunStore } from "../types-
|
|
1
|
+
import { a as ScheduleDefinitionRegistry, g as ScheduleRunStore } from "../types-DTVPVY5O.js";
|
|
2
2
|
import { LeaseStore } from "@vite-hub/runtime";
|
|
3
3
|
import { onShutdown } from "@vite-hub/runtime/internal/shutdown";
|
|
4
|
-
//#region src/runtime/process.d.ts
|
|
5
4
|
export interface ProcessScheduleRuntimeOptions {
|
|
6
5
|
/**
|
|
7
6
|
* How far back, in milliseconds, the runtime runs due minutes that it did not check, such as minutes during a
|
|
@@ -55,5 +54,4 @@ export interface ProcessScheduleTiming {
|
|
|
55
54
|
* Processes that share `leases` run each occurrence once between them. Call `close()` during host shutdown.
|
|
56
55
|
*/
|
|
57
56
|
export declare function installProcessScheduleRuntime(options: ProcessScheduleRuntimeOptions): Promise<ScheduleRuntimeController>;
|
|
58
|
-
//#endregion
|
|
59
57
|
export { onShutdown };
|
package/dist/runtime/process.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { n as isRecordOrFunction } from "../object-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { a as
|
|
6
|
-
import {
|
|
7
|
-
import { i as
|
|
8
|
-
import { createMemoryLeaseStore } from "@vite-hub/runtime";
|
|
9
|
-
import { hostname } from "node:os";
|
|
1
|
+
import { n as isRecordOrFunction } from "../object-CAK6UYR5.js";
|
|
2
|
+
import { n as isScheduleDue } from "../due-D-0trD1g.js";
|
|
3
|
+
import { t as scheduleErrorDiagnostics } from "../error-diagnostics-B1AaIGWP.js";
|
|
4
|
+
import { S as createScheduleError, b as scheduleIdempotencyKey, c as markLoggedScheduleError } from "../static-Bg7Jj92L.js";
|
|
5
|
+
import { a as executeStaticSchedule, l as toRunId } from "../started-errors-IG9DlT2A.js";
|
|
6
|
+
import { i as runStartedSchedules } from "../started-Bzvr4t5f.js";
|
|
7
|
+
import { a as getScheduleRuntimeRegistry, c as registerProcessScheduleDefinitions, d as setScheduleOccurrenceClaims, f as setScheduleRunStore, i as getScheduleRunStore, p as setScheduleRuntimeRegistry, r as getScheduleOccurrenceClaims } from "../state-BZLy46UJ.js";
|
|
8
|
+
import { createMemoryLeaseStore, getInstanceId } from "@vite-hub/runtime";
|
|
10
9
|
import { onShutdown } from "@vite-hub/runtime/internal/shutdown";
|
|
11
|
-
|
|
10
|
+
// src/internal/process-wake-runtime.ts
|
|
12
11
|
const minuteMs$1 = 6e4;
|
|
13
12
|
const DEFAULT_INTERVAL_MS = 6e4;
|
|
14
13
|
const DEFAULT_CONCURRENCY = 1;
|
|
@@ -42,11 +41,8 @@ function createProcessWakeDriver(options, context) {
|
|
|
42
41
|
const { catchUpMs, concurrency, intervalMs } = validateDriverOptions(options);
|
|
43
42
|
const now = options.now ?? (() => new Date(Date.now()));
|
|
44
43
|
let schedules = /* @__PURE__ */ new Map();
|
|
45
|
-
/** Occurrences waiting for a worker, in delivery order. */
|
|
46
44
|
const queued = /* @__PURE__ */ new Map();
|
|
47
|
-
/** Occurrences that a worker is waking now. */
|
|
48
45
|
const active = /* @__PURE__ */ new Set();
|
|
49
|
-
/** Schedules already queued for `occurrenceMinute`, so a Schedule wakes once per current minute. */
|
|
50
46
|
let dispatched = /* @__PURE__ */ new Set();
|
|
51
47
|
let occurrenceMinute;
|
|
52
48
|
let scannedThrough;
|
|
@@ -71,7 +67,7 @@ function createProcessWakeDriver(options, context) {
|
|
|
71
67
|
function take() {
|
|
72
68
|
for (const [key, input] of queued) {
|
|
73
69
|
queued.delete(key);
|
|
74
|
-
if (input.scheduledAt.getTime()
|
|
70
|
+
if (floorUTCMinute(now()) > (input.startBy ?? input.scheduledAt.getTime() + catchUpMs)) continue;
|
|
75
71
|
return input;
|
|
76
72
|
}
|
|
77
73
|
}
|
|
@@ -93,14 +89,12 @@ function createProcessWakeDriver(options, context) {
|
|
|
93
89
|
if (workers === 0) onIdle?.();
|
|
94
90
|
}
|
|
95
91
|
}
|
|
96
|
-
/** Starts workers up to `concurrency`. A free worker starts its wake before this returns. */
|
|
97
92
|
function startWorkers() {
|
|
98
93
|
while (workers < concurrency && queued.size > 0) {
|
|
99
94
|
workers += 1;
|
|
100
95
|
work();
|
|
101
96
|
}
|
|
102
97
|
}
|
|
103
|
-
/** Due occurrences of `entries` from `first` through `last`, oldest first. */
|
|
104
98
|
function dueOccurrences(entries, first, last) {
|
|
105
99
|
const due = [];
|
|
106
100
|
for (const schedule of entries) for (let minute = Math.ceil(first / minuteMs$1) * minuteMs$1; minute <= last; minute += minuteMs$1) {
|
|
@@ -119,7 +113,6 @@ function createProcessWakeDriver(options, context) {
|
|
|
119
113
|
}
|
|
120
114
|
return due.sort(byScheduledAt);
|
|
121
115
|
}
|
|
122
|
-
/** Queues occurrences that are not queued or running yet, then starts free workers. The current minute dispatches each Schedule once. */
|
|
123
116
|
function enqueue(due, currentMinute, retries = []) {
|
|
124
117
|
if (closing) return;
|
|
125
118
|
if (occurrenceMinute !== void 0 && currentMinute < occurrenceMinute) return;
|
|
@@ -160,7 +153,7 @@ function createProcessWakeDriver(options, context) {
|
|
|
160
153
|
reportError(error);
|
|
161
154
|
}
|
|
162
155
|
if (!latest) continue;
|
|
163
|
-
const first =
|
|
156
|
+
const first = Math.max(floorUTCMinute(latest) + minuteMs$1, currentMinute - catchUpMs);
|
|
164
157
|
due.push(...dueOccurrences([schedule], first, currentMinute - minuteMs$1));
|
|
165
158
|
}
|
|
166
159
|
enqueue(due.sort(byScheduledAt), currentMinute);
|
|
@@ -211,8 +204,7 @@ function createProcessWakeDriver(options, context) {
|
|
|
211
204
|
}
|
|
212
205
|
};
|
|
213
206
|
}
|
|
214
|
-
|
|
215
|
-
//#region src/runtime/claims.ts
|
|
207
|
+
// src/runtime/claims.ts
|
|
216
208
|
/** The lease key of one occurrence within an app's Schedule prefix. */
|
|
217
209
|
function occurrenceLeaseKey(runId, prefix = "vitehub:schedule") {
|
|
218
210
|
const base = prefix.replace(/^\/+|\/+$/g, "");
|
|
@@ -291,8 +283,7 @@ function createOccurrenceClaims(options) {
|
|
|
291
283
|
}
|
|
292
284
|
} };
|
|
293
285
|
}
|
|
294
|
-
|
|
295
|
-
//#region src/runtime/process.ts
|
|
286
|
+
// src/runtime/process.ts
|
|
296
287
|
function isStaticScheduleDefinition(value) {
|
|
297
288
|
return isRecordOrFunction(value) && Object.hasOwn(value, "cron") && Object.hasOwn(value, "handler") && typeof value.handler === "function";
|
|
298
289
|
}
|
|
@@ -303,7 +294,6 @@ function unwrapDefinition(loaded) {
|
|
|
303
294
|
function isTiming(value) {
|
|
304
295
|
return isRecordOrFunction(value) && String(value.cron) === value.cron && (value.timeZone === void 0 || String(value.timeZone) === value.timeZone);
|
|
305
296
|
}
|
|
306
|
-
/** Loads a Definition once, and again only after the load fails. */
|
|
307
297
|
function lazyDefinition(name, load) {
|
|
308
298
|
let loading;
|
|
309
299
|
return () => loading ??= load().then((loaded) => {
|
|
@@ -315,10 +305,6 @@ function lazyDefinition(name, load) {
|
|
|
315
305
|
throw error;
|
|
316
306
|
});
|
|
317
307
|
}
|
|
318
|
-
/**
|
|
319
|
-
* Loads the Definitions without a build timing now and keeps the others lazy. A Definition without a cron and a handler
|
|
320
|
-
* is skipped.
|
|
321
|
-
*/
|
|
322
308
|
async function loadStaticDefinitions(registry, timings = {}) {
|
|
323
309
|
const entries = await Promise.all(Object.entries(registry).map(async ([name, load]) => {
|
|
324
310
|
const timing = Object.hasOwn(timings, name) ? timings[name] : void 0;
|
|
@@ -373,15 +359,15 @@ async function installProcessScheduleRuntime(options) {
|
|
|
373
359
|
const previousClaims = getScheduleOccurrenceClaims();
|
|
374
360
|
const reportError = createErrorReporter(options.onError);
|
|
375
361
|
const leaseTtlMs = resolveLeaseTtlMs(options.leaseTtlMs);
|
|
362
|
+
const catchUpMs = options.catchUpMs ?? 36e5;
|
|
376
363
|
const claims = createOccurrenceClaims({
|
|
377
|
-
doneTtlMs:
|
|
364
|
+
doneTtlMs: catchUpMs + leaseTtlMs + 2 * minuteMs,
|
|
378
365
|
leases: options.leases ?? createMemoryLeaseStore(),
|
|
379
|
-
owner:
|
|
366
|
+
owner: getInstanceId(),
|
|
380
367
|
prefix: options.prefix,
|
|
381
368
|
reportError,
|
|
382
369
|
ttlMs: leaseTtlMs
|
|
383
370
|
});
|
|
384
|
-
/** Occurrences that another process held when this process tried them, by run id. Each scan tries them again. */
|
|
385
371
|
const held = /* @__PURE__ */ new Map();
|
|
386
372
|
const pendingWork = /* @__PURE__ */ new Set();
|
|
387
373
|
const activeWakes = /* @__PURE__ */ new Set();
|
|
@@ -402,20 +388,12 @@ async function installProcessScheduleRuntime(options) {
|
|
|
402
388
|
idPrefix: "srun_static_",
|
|
403
389
|
limit: 1
|
|
404
390
|
});
|
|
405
|
-
|
|
406
|
-
const limit = 100;
|
|
407
|
-
const recent = await options.scheduleRunStore.listRuns({
|
|
408
|
-
scheduleId,
|
|
409
|
-
limit
|
|
410
|
-
});
|
|
411
|
-
const latest = recent.find((record) => record.id.startsWith("srun_static_"));
|
|
412
|
-
if (latest) return latest.scheduledAt;
|
|
413
|
-
return recent.length < limit ? void 0 : "unknown";
|
|
391
|
+
return run?.scheduledAt;
|
|
414
392
|
},
|
|
415
393
|
reportError,
|
|
416
394
|
retries() {
|
|
417
|
-
const
|
|
418
|
-
for (const [runId, input] of held) if (input.scheduledAt.getTime()
|
|
395
|
+
const currentMinute = Math.floor((options.now?.() ?? /* @__PURE__ */ new Date()).getTime() / minuteMs) * minuteMs;
|
|
396
|
+
for (const [runId, input] of held) if (currentMinute > (input.startBy ?? input.scheduledAt.getTime() + catchUpMs)) held.delete(runId);
|
|
419
397
|
return [...held.values()];
|
|
420
398
|
},
|
|
421
399
|
wake(input) {
|
|
@@ -436,6 +414,7 @@ async function installProcessScheduleRuntime(options) {
|
|
|
436
414
|
return;
|
|
437
415
|
}
|
|
438
416
|
const runId = toRunId("static", entry.name, input.scheduledAt);
|
|
417
|
+
let logged = false;
|
|
439
418
|
try {
|
|
440
419
|
if (await claims.run(runId, (onExecution) => executeStaticSchedule({
|
|
441
420
|
claimed: true,
|
|
@@ -443,19 +422,24 @@ async function installProcessScheduleRuntime(options) {
|
|
|
443
422
|
definition,
|
|
444
423
|
name: entry.name,
|
|
445
424
|
onExecution,
|
|
425
|
+
onRunLogged: () => {
|
|
426
|
+
logged = true;
|
|
427
|
+
},
|
|
446
428
|
scheduledAt: input.scheduledAt,
|
|
447
429
|
waitUntil
|
|
448
430
|
})) === "held") held.set(runId, {
|
|
449
431
|
scheduleId: input.scheduleId,
|
|
450
|
-
scheduledAt: input.scheduledAt
|
|
432
|
+
scheduledAt: input.scheduledAt,
|
|
433
|
+
startBy: input.scheduledAt.getTime() + catchUpMs + leaseTtlMs + minuteMs
|
|
451
434
|
});
|
|
452
435
|
else held.delete(runId);
|
|
453
436
|
} catch (error) {
|
|
454
437
|
held.set(runId, {
|
|
438
|
+
...held.get(runId),
|
|
455
439
|
scheduleId: input.scheduleId,
|
|
456
440
|
scheduledAt: input.scheduledAt
|
|
457
441
|
});
|
|
458
|
-
throw error;
|
|
442
|
+
throw logged ? markLoggedScheduleError(error) : error;
|
|
459
443
|
}
|
|
460
444
|
})();
|
|
461
445
|
activeWakes.add(wake);
|
|
@@ -463,14 +447,7 @@ async function installProcessScheduleRuntime(options) {
|
|
|
463
447
|
return wake;
|
|
464
448
|
}
|
|
465
449
|
});
|
|
466
|
-
/**
|
|
467
|
-
* Catch-up starts after the newest cron-triggered run, also when that run did not finish. A run that is still pending
|
|
468
|
-
* or running inside the catch-up window lost its process, as when every server restarts after a crash. Try those
|
|
469
|
-
* occurrences again at each scan, through the claim: they run when the lease of their process ends and no process
|
|
470
|
-
* finished them.
|
|
471
|
-
*/
|
|
472
450
|
async function recoverUnfinishedOccurrences() {
|
|
473
|
-
const catchUpMs = options.catchUpMs ?? 36e5;
|
|
474
451
|
if (catchUpMs <= 0) return;
|
|
475
452
|
const currentMinute = Math.floor((options.now?.() ?? /* @__PURE__ */ new Date()).getTime() / minuteMs) * minuteMs;
|
|
476
453
|
const since = currentMinute - catchUpMs;
|
|
@@ -484,7 +461,7 @@ async function installProcessScheduleRuntime(options) {
|
|
|
484
461
|
scheduleId: entry.name
|
|
485
462
|
});
|
|
486
463
|
for (const run of runs) {
|
|
487
|
-
if (run.scheduledAt.getTime() < since
|
|
464
|
+
if (run.scheduledAt.getTime() < since) continue;
|
|
488
465
|
if (run.status !== "pending" && run.status !== "running") continue;
|
|
489
466
|
held.set(run.id, {
|
|
490
467
|
scheduleId: entry.name,
|
|
@@ -531,5 +508,4 @@ async function installProcessScheduleRuntime(options) {
|
|
|
531
508
|
})();
|
|
532
509
|
} };
|
|
533
510
|
}
|
|
534
|
-
//#endregion
|
|
535
511
|
export { installProcessScheduleRuntime, onShutdown };
|
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-BDEDVlyr.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,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { getHostScheduleInventory, getProcessScheduleDefinitions, getScheduleOccurrenceClaims, getScheduleRunStore, getScheduleRuntimeRegistry, getStartedScheduleRuntime, loadScheduleDefinition, registerProcessScheduleDefinitions, resetScheduleRuntime, setHostScheduleInventory, setScheduleOccurrenceClaims, setScheduleRunStore, setScheduleRuntimeRegistry, setStartedScheduleRuntime };
|
|
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-BZLy46UJ.js";
|
package/dist/runtime/static.d.ts
CHANGED
|
@@ -1,73 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
3
|
-
export interface ExecuteStaticScheduleOptions {
|
|
4
|
-
cron: string;
|
|
5
|
-
definition: ScheduleDefinition;
|
|
6
|
-
name: string;
|
|
7
|
-
scheduledAt?: Date;
|
|
8
|
-
waitUntil?: (promise: PromiseLike<unknown>) => void;
|
|
9
|
-
}
|
|
10
|
-
export interface ExecuteMatchingStaticSchedulesOptions {
|
|
11
|
-
cron: string;
|
|
12
|
-
/** Cron per Schedule name that the host registered in place of the Definition's cron. */
|
|
13
|
-
cronOverrides?: Readonly<Record<string, string>>;
|
|
14
|
-
registry: ScheduleDefinitionRegistry;
|
|
15
|
-
scheduledAt?: Date;
|
|
16
|
-
/**
|
|
17
|
-
* UTC cron that the host registered for each Schedule with a `timeZone`. A wake runs such a Schedule only when its
|
|
18
|
-
* own cron is due in its time zone at that minute. `cronOverrides` wins over this map.
|
|
19
|
-
*/
|
|
20
|
-
timeZoneCrons?: Readonly<Record<string, string>>;
|
|
21
|
-
waitUntil?: (promise: PromiseLike<unknown>) => void;
|
|
22
|
-
}
|
|
23
|
-
export interface ExecuteCloudflareStaticSchedulesOptions {
|
|
24
|
-
/** Cron per Schedule name that the host registered in place of the Definition's cron. */
|
|
25
|
-
cronOverrides?: Readonly<Record<string, string>>;
|
|
26
|
-
registry: ScheduleDefinitionRegistry;
|
|
27
|
-
/** UTC cron that the host registered for each Schedule with a `timeZone`. */
|
|
28
|
-
timeZoneCrons?: Readonly<Record<string, string>>;
|
|
29
|
-
waitUntil?: (promise: PromiseLike<unknown>) => void;
|
|
30
|
-
}
|
|
31
|
-
interface CloudflareScheduledEventLike {
|
|
32
|
-
[key: string]: unknown;
|
|
33
|
-
controller?: {
|
|
34
|
-
cron?: string;
|
|
35
|
-
scheduledTime?: number | string | Date;
|
|
36
|
-
};
|
|
37
|
-
cron?: string;
|
|
38
|
-
scheduledTime?: number | string | Date;
|
|
39
|
-
}
|
|
40
|
-
export interface StaticScheduleRun extends ScheduleRunContext {
|
|
41
|
-
cron: string;
|
|
42
|
-
scheduleId: string;
|
|
43
|
-
}
|
|
44
|
-
export declare function missingScheduleDefinitionError(name: string): Error;
|
|
45
|
-
/**
|
|
46
|
-
* Checks the `Authorization` header of a Vercel Cron request against `CRON_SECRET` in constant time.
|
|
47
|
-
*/
|
|
48
|
-
export declare function isScheduleCronAuthorized(authorization: string | null | undefined, cronSecret: string): boolean;
|
|
49
|
-
export declare function normalizeCron(cron: string): string;
|
|
50
|
-
export declare function normalizeScheduleRuntimeError(error: unknown): Error;
|
|
51
|
-
/**
|
|
52
|
-
* Estimates a wake minute from callback time when the host supplies no scheduled timestamp. This is the newest UTC
|
|
53
|
-
* cron match within one day, or the current minute when none matches. It cannot identify a delayed or retried wake
|
|
54
|
-
* after another cron match; callers must not treat it as the provider's occurrence identity.
|
|
55
|
-
*/
|
|
56
|
-
export declare function scheduledWakeTime(cron: string, now?: Date): Date;
|
|
57
|
-
/**
|
|
58
|
-
* Returns `true` when a host wake at `scheduledAt` is an occurrence of the Definition's cron in its `timeZone`. The host
|
|
59
|
-
* runs a wider UTC cron for a time-zoned Schedule, so the runtime skips the wakes that are not local occurrences.
|
|
60
|
-
*/
|
|
61
|
-
export declare function isTimeZoneWakeDue(definition: ScheduleDefinition & {
|
|
62
|
-
cron: string;
|
|
63
|
-
}, name: string, scheduledAt: Date): boolean;
|
|
64
|
-
export declare function createStaticScheduleRun(options: Omit<ExecuteStaticScheduleOptions, "definition" | "waitUntil"> & {
|
|
65
|
-
waitUntil: NonNullable<ExecuteStaticScheduleOptions["waitUntil"]>;
|
|
66
|
-
}): StaticScheduleRun;
|
|
67
|
-
export declare function executeStaticSchedule(options: ExecuteStaticScheduleOptions): Promise<unknown>;
|
|
68
|
-
export declare function executeMatchingStaticSchedules(options: ExecuteMatchingStaticSchedulesOptions): Promise<unknown[]>;
|
|
69
|
-
export declare function executeCloudflareStaticSchedules(event: CloudflareScheduledEventLike, options: ExecuteCloudflareStaticSchedulesOptions): Promise<unknown[]>;
|
|
70
|
-
export declare function unwrapScheduleDefinition(loaded: unknown): (ScheduleDefinition & {
|
|
71
|
-
cron: string;
|
|
72
|
-
}) | undefined;
|
|
73
|
-
//#endregion
|
|
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-DeRvJqcQ.js";
|
|
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,2 +1,3 @@
|
|
|
1
|
-
import { a as isScheduleCronAuthorized, c as
|
|
2
|
-
|
|
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-Bg7Jj92L.js";
|
|
2
|
+
import { t as cronWithWeekdayNames } from "../due-D-0trD1g.js";
|
|
3
|
+
export { createStaticScheduleRun, cronWithWeekdayNames, executeCloudflareStaticSchedules, executeMatchingStaticSchedules, executeStaticSchedule, isScheduleCronAuthorized, isTimeZoneWakeDue, logScheduleRuntimeError, markLoggedScheduleError, missingScheduleDefinitionError, normalizeCron, normalizeScheduleRuntimeError, scheduledWakeTime, unwrapScheduleDefinition };
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/// <reference path="./registry-module.d.ts" />
|
|
2
|
-
import { a as
|
|
3
|
-
import {
|
|
4
|
-
import { n as createScheduleKVStorage, t as ScheduleKVStorage } from "./kv-storage-
|
|
5
|
-
import {
|
|
6
|
-
import { a as getScheduleRunStore, p as setScheduleRunStore, u as resetScheduleRuntime } from "./state-
|
|
7
|
-
//#region src/runtime/started.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-CEv3cScg.js";
|
|
3
|
+
import { _ as unwrapScheduleDefinition, m as normalizeCron } from "./static-DeRvJqcQ.js";
|
|
4
|
+
import { n as createScheduleKVStorage, t as ScheduleKVStorage } from "./kv-storage-hI2IOjb5.js";
|
|
5
|
+
import { a as ScheduleDefinitionRegistry, b as StartedScheduleStore, c as ScheduleRunAttemptRecord, f as ScheduleRunListOptions, g as ScheduleRunStore, i as ScheduleDefinitionOptions, n as ScheduleDefinition, o as ScheduleHandler, p as ScheduleRunRecord, s as ScheduleRegistryDefinition, u as ScheduleRunContext } from "./types-DTVPVY5O.js";
|
|
6
|
+
import { a as getScheduleRunStore, p as setScheduleRunStore, u as resetScheduleRuntime } from "./state-BDEDVlyr.js";
|
|
8
7
|
interface InstallStartedSchedulesOptions {
|
|
9
8
|
/**
|
|
10
9
|
* How far back, in milliseconds, the first tick after a start runs cron minutes that no tick checked. Use it only with
|
|
@@ -35,5 +34,4 @@ export declare function createKVStartedScheduleStore(options: KVStartedScheduleS
|
|
|
35
34
|
* that started Schedule and logged; it does not fail the tick.
|
|
36
35
|
*/
|
|
37
36
|
export declare function runStartedSchedules(context: ScheduleRunContext): Promise<void>;
|
|
38
|
-
//#endregion
|
|
39
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 };
|
package/dist/runtime.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as executeStaticSchedule, c as runScheduleFrom, i as executeSchedule, n as createScheduleRun } from "./started-errors-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { i as runStartedSchedules, n as createMemoryStartedScheduleStore, r as installStartedSchedules, t as createKVStartedScheduleStore } from "./started-
|
|
1
|
+
import { a as executeStaticSchedule, c as runScheduleFrom, i as executeSchedule, n as createScheduleRun } from "./started-errors-IG9DlT2A.js";
|
|
2
|
+
import { p as unwrapScheduleDefinition, u as normalizeCron } from "./static-Bg7Jj92L.js";
|
|
3
|
+
import { t as createScheduleKVStorage } from "./kv-storage-Dsr3TL9c.js";
|
|
4
|
+
import { f as setScheduleRunStore, g as createMemoryScheduleRunStore, h as createKVScheduleRunStore, i as getScheduleRunStore, l as resetScheduleRuntime } from "./state-BZLy46UJ.js";
|
|
5
|
+
import { i as runStartedSchedules, n as createMemoryStartedScheduleStore, r as installStartedSchedules, t as createKVStartedScheduleStore } from "./started-Bzvr4t5f.js";
|
|
6
6
|
export { createKVScheduleRunStore, createKVStartedScheduleStore, createMemoryScheduleRunStore, createMemoryStartedScheduleStore, createScheduleKVStorage, createScheduleRun, executeSchedule, executeStaticSchedule, getScheduleRunStore, installStartedSchedules, normalizeCron, resetScheduleRuntime, runScheduleFrom, runStartedSchedules, setScheduleRunStore, unwrapScheduleDefinition };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { o as getStartedScheduleRuntime } from "./state-
|
|
1
|
+
import { t as startedScheduleErrors, u as randomId } from "./started-errors-IG9DlT2A.js";
|
|
2
|
+
import { t as isIanaTimeZone } from "./time-zone-pMp_g8Uu.js";
|
|
3
|
+
import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
|
|
4
|
+
import { y as parseScheduledAt } from "./static-Bg7Jj92L.js";
|
|
5
|
+
import { o as getStartedScheduleRuntime } from "./state-BZLy46UJ.js";
|
|
6
6
|
import { parseCronExpression } from "cron-schedule";
|
|
7
|
-
|
|
7
|
+
// src/started.ts
|
|
8
8
|
const optionKeys = /* @__PURE__ */ new Set([
|
|
9
9
|
"at",
|
|
10
10
|
"cron",
|
|
@@ -51,7 +51,6 @@ function isFiveFieldCron(cron) {
|
|
|
51
51
|
return false;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
/** Reads the options once at the boundary. The returned record is what the store keeps. */
|
|
55
54
|
function parseOptions(name, options) {
|
|
56
55
|
if (!isRecordOrFunction(options)) return invalid("pass an object with `at` or `cron`.");
|
|
57
56
|
const unknownKey = Object.keys(options).find((key) => !optionKeys.has(key));
|
|
@@ -142,5 +141,4 @@ async function cancelSchedule(id) {
|
|
|
142
141
|
if (storeError) return [storeError, void 0];
|
|
143
142
|
return deleted ? [void 0, schedule] : [startedScheduleErrors.SCHEDULE_NOT_FOUND({ id: String(id) }), void 0];
|
|
144
143
|
}
|
|
145
|
-
//#endregion
|
|
146
144
|
export { startSchedule as i, getSchedule as n, listSchedules as r, cancelSchedule as t };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import { i as executeSchedule, l as toRunId, t as startedScheduleErrors } from "./started-errors-
|
|
3
|
-
import { _ as joinKey, m as setStartedScheduleRuntime, o as getStartedScheduleRuntime, r as getScheduleOccurrenceClaims, v as keySegments } from "./state-
|
|
4
|
-
import {
|
|
1
|
+
import { n as isScheduleDue } from "./due-D-0trD1g.js";
|
|
2
|
+
import { i as executeSchedule, l as toRunId, t as startedScheduleErrors } from "./started-errors-IG9DlT2A.js";
|
|
3
|
+
import { _ as joinKey, m as setStartedScheduleRuntime, o as getStartedScheduleRuntime, r as getScheduleOccurrenceClaims, v as keySegments } from "./state-BZLy46UJ.js";
|
|
4
|
+
import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
|
|
5
|
+
import { _ as errorCode, v as logFailure } from "./static-Bg7Jj92L.js";
|
|
5
6
|
import { normalizeRuntimeDiagnosticError } from "@vite-hub/runtime";
|
|
6
|
-
|
|
7
|
+
// src/runtime/started.ts
|
|
7
8
|
const minuteMs = 6e4;
|
|
8
9
|
/** Installs the store and the Definitions that `startSchedule()` and the tick use. The generated Nitro plugin calls it. */
|
|
9
10
|
function installStartedSchedules(options) {
|
|
@@ -99,7 +100,6 @@ function unwrapStartableDefinition(loaded) {
|
|
|
99
100
|
const candidate = isRecordOrFunction(loaded) && Object.hasOwn(loaded, "default") ? loaded.default : loaded;
|
|
100
101
|
return isRecordOrFunction(candidate) && typeof candidate.handler === "function" && !Object.hasOwn(candidate, "cron") ? candidate : void 0;
|
|
101
102
|
}
|
|
102
|
-
/** The minutes in `[first, last]` when `schedule` is due, after it was created. A one-time Schedule is due once `at` passed. */
|
|
103
103
|
function dueMinutes(schedule, first, last) {
|
|
104
104
|
if (schedule.at) return schedule.at.getTime() <= last ? [schedule.at] : [];
|
|
105
105
|
const due = [];
|
|
@@ -114,7 +114,6 @@ function dueMinutes(schedule, first, last) {
|
|
|
114
114
|
}
|
|
115
115
|
return due;
|
|
116
116
|
}
|
|
117
|
-
/** Runs one occurrence of a started Schedule. Resolves `false` when another process holds it, so a later tick tries again. */
|
|
118
117
|
async function runOccurrence(runtime, schedule, scheduledAt, waitUntil) {
|
|
119
118
|
const definition = unwrapStartableDefinition(await (Object.hasOwn(runtime.registry, schedule.name) ? runtime.registry[schedule.name] : void 0)?.());
|
|
120
119
|
if (!definition) {
|
|
@@ -169,6 +168,8 @@ async function runStartedSchedules(context) {
|
|
|
169
168
|
})));
|
|
170
169
|
const held = runtime.held ??= /* @__PURE__ */ new Map();
|
|
171
170
|
const byId = new Map(schedules.map((schedule) => [schedule.id, schedule]));
|
|
171
|
+
const failing = runtime.failing ??= /* @__PURE__ */ new Map();
|
|
172
|
+
for (const id of failing.keys()) if (!byId.has(id)) failing.delete(id);
|
|
172
173
|
for (const [runId, entry] of held) {
|
|
173
174
|
const schedule = byId.get(entry.scheduleId);
|
|
174
175
|
if (!schedule) held.delete(runId);
|
|
@@ -187,15 +188,31 @@ async function runStartedSchedules(context) {
|
|
|
187
188
|
scheduleId: schedule.id,
|
|
188
189
|
scheduledAt
|
|
189
190
|
});
|
|
191
|
+
failing.delete(schedule.id);
|
|
190
192
|
return;
|
|
191
193
|
}
|
|
192
194
|
held.set(runId, {
|
|
193
195
|
scheduleId: schedule.id,
|
|
194
196
|
scheduledAt
|
|
195
197
|
});
|
|
196
|
-
|
|
198
|
+
const cause = errorCode(result.reason) ?? (result.reason instanceof Error ? result.reason.message : String(result.reason));
|
|
199
|
+
if (failing.get(schedule.id) === cause) return;
|
|
200
|
+
failing.set(schedule.id, cause);
|
|
201
|
+
logFailure({
|
|
202
|
+
field: "schedule",
|
|
203
|
+
fields: {
|
|
204
|
+
op: "started",
|
|
205
|
+
name: schedule.name,
|
|
206
|
+
id: schedule.id
|
|
207
|
+
},
|
|
208
|
+
level: "error",
|
|
209
|
+
message: "Started Schedule failed",
|
|
210
|
+
error: result.reason,
|
|
211
|
+
waitUntil: (promise) => context.waitUntil(promise)
|
|
212
|
+
}, () => {
|
|
213
|
+
console.error(`[vitehub:schedule] Started Schedule "${schedule.id}" of "${schedule.name}" failed.`, normalizeRuntimeDiagnosticError(result.reason, { includeStack: true }));
|
|
214
|
+
});
|
|
197
215
|
});
|
|
198
216
|
if (results.every((result) => result.status === "fulfilled")) runtime.checkedThrough = Math.max(runtime.checkedThrough ?? minute, minute);
|
|
199
217
|
}
|
|
200
|
-
//#endregion
|
|
201
218
|
export { runStartedSchedules as i, createMemoryStartedScheduleStore as n, installStartedSchedules as r, createKVStartedScheduleStore as t };
|