@vite-hub/schedule 0.1.0 → 0.3.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 +114 -96
- package/dist/console-wEhr0LWn.d.ts +330 -0
- package/dist/definition.d.ts +6 -2
- package/dist/definition.js +47 -1
- package/dist/due-BVMRQ93v.js +144 -0
- package/dist/durability.d.ts +14 -0
- package/dist/durability.js +23 -0
- package/dist/error-diagnostics-DSkCJC_L.js +266 -0
- package/dist/error-diagnostics-Mpeks7J0.js +166 -0
- package/dist/index.d.ts +59 -5
- package/dist/index.js +27 -2
- package/dist/invariant-DolT9EEx.js +22 -0
- package/dist/{kv-storage-Bv9ocZT-.d.ts → kv-storage-C0KZZB6v.d.ts} +2 -2
- package/dist/{kv-storage-DWinmLLy.js → kv-storage-iJChCS5A.js} +2 -2
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-8gOe-ubD.d.ts} +37 -15
- package/dist/{operations-gk2qzhYV.js → operations-DwZWFIUX.js} +75 -22
- package/dist/operations.d.ts +27 -4
- package/dist/operations.js +127 -730
- package/dist/os.d.ts +167 -0
- package/dist/os.js +1659 -0
- package/dist/runtime/console.d.ts +12 -0
- package/dist/runtime/console.js +85 -0
- package/dist/runtime/kv.d.ts +1 -1
- package/dist/runtime/kv.js +1 -1
- package/dist/runtime/process.d.ts +32 -5
- package/dist/runtime/process.js +401 -413
- package/dist/runtime/state.d.ts +2 -9
- package/dist/runtime/state.js +2 -2
- package/dist/runtime/static.d.ts +28 -2
- package/dist/runtime/static.js +2 -2
- package/dist/runtime.d.ts +34 -32
- package/dist/runtime.js +6 -5
- package/dist/started-BuGmnus4.js +201 -0
- package/dist/started-Bx7MDbrl.js +146 -0
- package/dist/{execute-BJrgNgQ0.js → started-errors-p7cu_rI7.js} +69 -20
- package/dist/{state-DSxmHPn3.js → state-B-Fuyfb4.js} +42 -22
- package/dist/state-Do2wV4Tx.d.ts +49 -0
- package/dist/{static-6g82xguw.js → static-DQwzzvPg.js} +63 -42
- package/dist/store-Df0-fzCl.d.ts +53 -0
- package/dist/time-zone-SBldrUgt.js +59 -0
- package/dist/{types-CHdV9FQU.d.ts → types-Cw5LjPuc.d.ts} +62 -8
- package/dist/vite.d.ts +255 -2
- package/dist/vite.js +5876 -2
- package/dist/{wait-until-BmIqRo4x.js → wait-until-Dy4Bn3ZN.js} +26 -1
- package/package.json +19 -24
- package/dist/definition-CMiOg1lg.js +0 -111
- package/dist/error-diagnostics-A_8Kp-48.js +0 -116
- package/dist/error-diagnostics-in7mif5s.js +0 -45
- package/dist/nuxt.d.ts +0 -17
- package/dist/nuxt.js +0 -27
- package/dist/store-QAOd8bxm.d.ts +0 -11
- package/dist/vite-BAVyZ8hZ.d.ts +0 -474
- package/dist/vite-BJwZkMrn.js +0 -5193
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as ViteHubConsoleRecord } from "../console-wEhr0LWn.js";
|
|
2
|
+
//#region src/runtime/console.d.ts
|
|
3
|
+
/** The Cron column of the Console: the cron, with the time zone when it is not UTC. */
|
|
4
|
+
export declare function scheduleConsoleTiming(cron: string, timeZone: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* The cron and time zone of each Schedule that this process runs, read from the loaded Definitions on each Console
|
|
7
|
+
* request, and one record for each Schedule that code started with `startSchedule()`. Each Definition record updates the
|
|
8
|
+
* build-time record of its Schedule. Without a Process Runtime, provider cron output uses the static UTC cron that the
|
|
9
|
+
* build checked.
|
|
10
|
+
*/
|
|
11
|
+
export declare function readScheduleConsoleRecords(): Promise<ViteHubConsoleRecord[]>;
|
|
12
|
+
//#endregion
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { a as getStartedScheduleRuntime, t as getProcessScheduleDefinitions } from "../state-B-Fuyfb4.js";
|
|
2
|
+
//#region src/runtime/console.ts
|
|
3
|
+
/** The Cron column of the Console: the cron, with the time zone when it is not UTC. */
|
|
4
|
+
function scheduleConsoleTiming(cron, timeZone) {
|
|
5
|
+
return timeZone === "UTC" ? cron : `${cron} (${timeZone})`;
|
|
6
|
+
}
|
|
7
|
+
function startedScheduleRecord(schedule) {
|
|
8
|
+
const timeZone = schedule.timeZone ?? "UTC";
|
|
9
|
+
const timing = schedule.at ? `once at ${schedule.at.toISOString()}` : scheduleConsoleTiming(schedule.cron ?? "", timeZone);
|
|
10
|
+
return {
|
|
11
|
+
cells: {
|
|
12
|
+
manual: "-",
|
|
13
|
+
schedule: `${schedule.name} (${schedule.id})`,
|
|
14
|
+
timing
|
|
15
|
+
},
|
|
16
|
+
fields: [
|
|
17
|
+
{
|
|
18
|
+
label: "Kind",
|
|
19
|
+
value: "Started schedule"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
label: "ID",
|
|
23
|
+
value: schedule.id
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
label: "Definition",
|
|
27
|
+
value: schedule.name
|
|
28
|
+
},
|
|
29
|
+
...schedule.at ? [{
|
|
30
|
+
label: "Runs at",
|
|
31
|
+
value: schedule.at.toISOString()
|
|
32
|
+
}] : [{
|
|
33
|
+
label: "Cron",
|
|
34
|
+
value: schedule.cron ?? ""
|
|
35
|
+
}, {
|
|
36
|
+
label: "Time zone",
|
|
37
|
+
value: timeZone
|
|
38
|
+
}],
|
|
39
|
+
{
|
|
40
|
+
label: "Started at",
|
|
41
|
+
value: schedule.createdAt.toISOString()
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
label: "Payload",
|
|
45
|
+
value: schedule.payload === void 0 ? "-" : JSON.stringify(schedule.payload)
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
label: "Runs",
|
|
49
|
+
value: `Use \`vitehub schedule runs ${schedule.id}\` to list its runs, and \`vitehub schedule cancel ${schedule.id}\` to stop it.`
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
id: `started:${schedule.id}`
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The cron and time zone of each Schedule that this process runs, read from the loaded Definitions on each Console
|
|
57
|
+
* request, and one record for each Schedule that code started with `startSchedule()`. Each Definition record updates the
|
|
58
|
+
* build-time record of its Schedule. Without a Process Runtime, provider cron output uses the static UTC cron that the
|
|
59
|
+
* build checked.
|
|
60
|
+
*/
|
|
61
|
+
async function readScheduleConsoleRecords() {
|
|
62
|
+
const records = [...getProcessScheduleDefinitions() ?? []].flatMap(([name, definition]) => {
|
|
63
|
+
if (definition.cron === void 0) return [];
|
|
64
|
+
const timeZone = definition.timeZone ?? "UTC";
|
|
65
|
+
return [{
|
|
66
|
+
cells: {
|
|
67
|
+
schedule: name,
|
|
68
|
+
timing: scheduleConsoleTiming(definition.cron, timeZone)
|
|
69
|
+
},
|
|
70
|
+
fields: [{
|
|
71
|
+
label: "Cron",
|
|
72
|
+
value: definition.cron
|
|
73
|
+
}, {
|
|
74
|
+
label: "Time zone",
|
|
75
|
+
value: timeZone
|
|
76
|
+
}],
|
|
77
|
+
id: `definition:${name}`
|
|
78
|
+
}];
|
|
79
|
+
});
|
|
80
|
+
const started = getStartedScheduleRuntime();
|
|
81
|
+
if (!started) return records;
|
|
82
|
+
return [...records, ...(await started.store.list()).map(startedScheduleRecord)];
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { readScheduleConsoleRecords, scheduleConsoleTiming };
|
package/dist/runtime/kv.d.ts
CHANGED
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-iJChCS5A.js";
|
|
2
2
|
import * as kvPackage from "@vite-hub/kv";
|
|
3
3
|
//#region src/runtime/kv.ts
|
|
4
4
|
const scheduleKVStorage = createScheduleKVStorage(kvPackage.kv);
|
|
@@ -1,31 +1,58 @@
|
|
|
1
|
-
import { a as ScheduleDefinitionRegistry, g as ScheduleRunStore } from "../types-
|
|
2
|
-
import {
|
|
1
|
+
import { a as ScheduleDefinitionRegistry, g as ScheduleRunStore } from "../types-Cw5LjPuc.js";
|
|
2
|
+
import { LeaseStore } from "@vite-hub/runtime";
|
|
3
|
+
import { onShutdown } from "@vite-hub/runtime/internal/shutdown";
|
|
3
4
|
//#region src/runtime/process.d.ts
|
|
4
5
|
export interface ProcessScheduleRuntimeOptions {
|
|
5
6
|
/**
|
|
6
7
|
* How far back, in milliseconds, the runtime runs due minutes that it did not check, such as minutes during a
|
|
7
|
-
* restart. It
|
|
8
|
+
* restart. It catches up Schedules with a prior cron-triggered run, or indeterminate legacy history.
|
|
9
|
+
* Defaults to one hour. `0` disables it.
|
|
8
10
|
*/
|
|
9
11
|
catchUpMs?: number;
|
|
10
12
|
/** Maximum number of Schedule runs at the same time. Defaults to `1`. */
|
|
11
13
|
concurrency?: number;
|
|
12
14
|
/** Milliseconds between two checks, from 1 to 60000. Defaults to `60000`. */
|
|
13
15
|
intervalMs?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Milliseconds that a process holds an occurrence after it stops renewing it, for example after a crash. Then another
|
|
18
|
+
* process runs the occurrence, if no process finished it. The holder renews it every third of this time. Defaults to
|
|
19
|
+
* `60000`.
|
|
20
|
+
*/
|
|
21
|
+
leaseTtlMs?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Where processes claim each occurrence, so one process runs it. Give every process the same shared store, such as
|
|
24
|
+
* `createSqlLeaseStore()` from `@vite-hub/runtime` on the app Database. Defaults to `createMemoryLeaseStore()`, which
|
|
25
|
+
* works for one process only.
|
|
26
|
+
*/
|
|
27
|
+
leases?: LeaseStore;
|
|
14
28
|
/** Clock for tests. Defaults to the system clock. */
|
|
15
29
|
now?: () => Date;
|
|
16
30
|
onError?: (error: unknown) => void;
|
|
31
|
+
/** Namespace for occurrence leases. Use the same prefix as the app's Schedule stores. Defaults to `vitehub:schedule`. */
|
|
32
|
+
prefix?: string;
|
|
17
33
|
/** Static Schedule Definitions that this process runs on their cron. */
|
|
18
34
|
registry: ScheduleDefinitionRegistry;
|
|
19
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* The cron and time zone that the build read from the source of each Schedule in `registry`. The runtime loads the
|
|
37
|
+
* module of a Schedule listed here when it is due, not at startup. It loads the other Schedules at startup.
|
|
38
|
+
*/
|
|
39
|
+
timings?: Readonly<Record<string, ProcessScheduleTiming>>;
|
|
40
|
+
/** Stores Schedule Runs. Catch-up after a restart reads the newest cron-triggered run of each Schedule from it. */
|
|
20
41
|
scheduleRunStore: ScheduleRunStore;
|
|
21
42
|
}
|
|
22
43
|
export interface ScheduleRuntimeController {
|
|
23
44
|
close(): Promise<void>;
|
|
24
45
|
}
|
|
46
|
+
/** The cron of a Schedule and its time zone, UTC when not set. */
|
|
47
|
+
export interface ProcessScheduleTiming {
|
|
48
|
+
cron: string;
|
|
49
|
+
timeZone?: string;
|
|
50
|
+
}
|
|
25
51
|
/**
|
|
26
52
|
* Runs Static Schedule Definitions on their cron, in their `timeZone` (UTC by default), in this long-running process. It checks every minute, runs each
|
|
27
53
|
* due minute once, and records each run in `scheduleRunStore`. After a restart it runs the minutes that no process
|
|
28
|
-
* checked, within `catchUpMs`, for Schedules
|
|
54
|
+
* checked, within `catchUpMs`, for Schedules with a prior cron-triggered run or indeterminate legacy history.
|
|
55
|
+
* Processes that share `leases` run each occurrence once between them. Call `close()` during host shutdown.
|
|
29
56
|
*/
|
|
30
57
|
export declare function installProcessScheduleRuntime(options: ProcessScheduleRuntimeOptions): Promise<ScheduleRuntimeController>;
|
|
31
58
|
//#endregion
|