@vite-hub/schedule 0.0.4 → 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.
Files changed (62) hide show
  1. package/README.md +139 -58
  2. package/dist/console-wEhr0LWn.d.ts +330 -0
  3. package/dist/definition.d.ts +8 -6
  4. package/dist/definition.js +34 -28
  5. package/dist/due-BVMRQ93v.js +144 -0
  6. package/dist/durability.d.ts +14 -0
  7. package/dist/durability.js +23 -0
  8. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  9. package/dist/error-diagnostics-Mpeks7J0.js +166 -0
  10. package/dist/index.d.ts +61 -40
  11. package/dist/index.js +27 -7
  12. package/dist/inspect-DTfAo5gS.js +118 -0
  13. package/dist/invariant-DolT9EEx.js +22 -0
  14. package/dist/kv-storage-C0KZZB6v.d.ts +18 -0
  15. package/dist/{kv-storage-DWinmLLy.js → kv-storage-iJChCS5A.js} +2 -2
  16. package/dist/object-Da1zyPCR.js +11 -0
  17. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  18. package/dist/operations-DwZWFIUX.js +184 -0
  19. package/dist/operations.d.ts +84 -0
  20. package/dist/operations.js +318 -0
  21. package/dist/os.d.ts +167 -0
  22. package/dist/os.js +1659 -0
  23. package/dist/registry-module.d.ts +0 -5
  24. package/dist/runtime/console.d.ts +12 -0
  25. package/dist/runtime/console.js +85 -0
  26. package/dist/runtime/kv.d.ts +4 -0
  27. package/dist/{kv-BJ1I9IlJ.js → runtime/kv.js} +1 -1
  28. package/dist/runtime/process.d.ts +53 -5
  29. package/dist/runtime/process.js +501 -251
  30. package/dist/runtime/state.d.ts +2 -13
  31. package/dist/runtime/state.js +2 -2
  32. package/dist/runtime/static.d.ts +44 -12
  33. package/dist/runtime/static.js +2 -150
  34. package/dist/runtime.d.ts +38 -4
  35. package/dist/runtime.js +6 -3
  36. package/dist/started-BuGmnus4.js +201 -0
  37. package/dist/started-Bx7MDbrl.js +146 -0
  38. package/dist/started-errors-p7cu_rI7.js +250 -0
  39. package/dist/state-B-Fuyfb4.js +468 -0
  40. package/dist/state-Do2wV4Tx.d.ts +49 -0
  41. package/dist/static-DQwzzvPg.js +266 -0
  42. package/dist/store-Df0-fzCl.d.ts +53 -0
  43. package/dist/time-zone-SBldrUgt.js +59 -0
  44. package/dist/types-Cw5LjPuc.d.ts +167 -0
  45. package/dist/vite.d.ts +214 -11
  46. package/dist/vite.js +5876 -3
  47. package/dist/wait-until-Dy4Bn3ZN.js +112 -0
  48. package/package.json +65 -24
  49. package/dist/client-DpCD4YFE.js +0 -233
  50. package/dist/discovery-DkFAN7Wd.d.ts +0 -15
  51. package/dist/discovery-DvU3B6iD.js +0 -753
  52. package/dist/due-Bbh4yIxq.js +0 -59
  53. package/dist/execute-B-pii4wf.js +0 -211
  54. package/dist/nuxt.d.ts +0 -19
  55. package/dist/nuxt.js +0 -26
  56. package/dist/runtime/driver.d.ts +0 -26
  57. package/dist/runtime/driver.js +0 -337
  58. package/dist/state-By7WU_ks.js +0 -472
  59. package/dist/store-t-74rsM_.d.ts +0 -48
  60. package/dist/types-Bcje4dLV.d.ts +0 -136
  61. package/dist/vite-BHs17nWX.js +0 -4166
  62. package/dist/wait-until-BzIwzXw4.js +0 -23
@@ -2,8 +2,3 @@ declare module "#vitehub/schedule/registry" {
2
2
  const registry: import("@vite-hub/schedule").ScheduleDefinitionRegistry
3
3
  export default registry
4
4
  }
5
-
6
- declare module "#vitehub/schedule/targets" {
7
- export const scheduleTargetNames: import("@vite-hub/schedule").ScheduleTargetName[]
8
- export type ScheduleTargetName = import("@vite-hub/schedule").ScheduleTargetName
9
- }
@@ -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 };
@@ -0,0 +1,4 @@
1
+ import { t as ScheduleKVStorage } from "../kv-storage-C0KZZB6v.js";
2
+ //#region src/runtime/kv.d.ts
3
+ export declare const scheduleKVStorage: ScheduleKVStorage;
4
+ //#endregion
@@ -1,4 +1,4 @@
1
- import { t as createScheduleKVStorage } from "./kv-storage-DWinmLLy.js";
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,11 +1,59 @@
1
- import { RuntimeScheduleWakeDriverFactory } from "./driver.js";
2
-
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
- interface ProcessScheduleWakeDriverOptions {
5
+ export interface ProcessScheduleRuntimeOptions {
6
+ /**
7
+ * How far back, in milliseconds, the runtime runs due minutes that it did not check, such as minutes during a
8
+ * restart. It catches up Schedules with a prior cron-triggered run, or indeterminate legacy history.
9
+ * Defaults to one hour. `0` disables it.
10
+ */
11
+ catchUpMs?: number;
12
+ /** Maximum number of Schedule runs at the same time. Defaults to `1`. */
5
13
  concurrency?: number;
14
+ /** Milliseconds between two checks, from 1 to 60000. Defaults to `60000`. */
6
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;
28
+ /** Clock for tests. Defaults to the system clock. */
7
29
  now?: () => Date;
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;
33
+ /** Static Schedule Definitions that this process runs on their cron. */
34
+ registry: ScheduleDefinitionRegistry;
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. */
41
+ scheduleRunStore: ScheduleRunStore;
8
42
  }
9
- declare function createProcessScheduleWakeDriver(options?: ProcessScheduleWakeDriverOptions): RuntimeScheduleWakeDriverFactory;
43
+ export interface ScheduleRuntimeController {
44
+ close(): Promise<void>;
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
+ }
51
+ /**
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
53
+ * due minute once, and records each run in `scheduleRunStore`. After a restart it runs the minutes that no process
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.
56
+ */
57
+ export declare function installProcessScheduleRuntime(options: ProcessScheduleRuntimeOptions): Promise<ScheduleRuntimeController>;
10
58
  //#endregion
11
- export { ProcessScheduleWakeDriverOptions, createProcessScheduleWakeDriver };
59
+ export { onShutdown };