@vite-hub/schedule 0.0.3 → 0.1.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/LICENSE +201 -0
- package/README.md +199 -65
- package/dist/definition-CMiOg1lg.js +111 -0
- package/dist/definition.d.ts +4 -6
- package/dist/definition.js +2 -42
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-in7mif5s.js +45 -0
- package/dist/execute-BJrgNgQ0.js +201 -0
- package/dist/index.d.ts +7 -51
- package/dist/index.js +2 -7
- package/dist/inspect-DTfAo5gS.js +118 -0
- package/dist/kv-storage-Bv9ocZT-.d.ts +18 -0
- package/dist/nuxt.d.ts +4 -6
- package/dist/nuxt.js +3 -1
- package/dist/operations-gk2qzhYV.js +131 -0
- package/dist/operations-tNUdj3G4.d.ts +212 -0
- package/dist/operations.d.ts +61 -0
- package/dist/operations.js +921 -0
- package/dist/registry-module.d.ts +0 -5
- package/dist/runtime/kv.d.ts +4 -0
- package/dist/{kv-BJ1I9IlJ.js → runtime/kv.js} +1 -1
- package/dist/runtime/process.d.ts +26 -5
- package/dist/runtime/process.js +337 -75
- package/dist/runtime/state.d.ts +8 -12
- package/dist/runtime/state.js +2 -2
- package/dist/runtime/static.d.ts +18 -12
- package/dist/runtime/static.js +2 -138
- package/dist/runtime.d.ts +36 -4
- package/dist/runtime.js +5 -3
- package/dist/state-DSxmHPn3.js +448 -0
- package/dist/static-6g82xguw.js +245 -0
- package/dist/store-QAOd8bxm.d.ts +11 -0
- package/dist/types-CHdV9FQU.d.ts +113 -0
- package/dist/vite-BAVyZ8hZ.d.ts +474 -0
- package/dist/vite-BJwZkMrn.js +5193 -0
- package/dist/vite.d.ts +2 -38
- package/dist/vite.js +2 -2
- package/dist/wait-until-BmIqRo4x.js +87 -0
- package/package.json +68 -22
- package/dist/client-BMFCy0dX.js +0 -233
- package/dist/discovery-BZlat3Kc.js +0 -776
- package/dist/due-Bbh4yIxq.js +0 -59
- package/dist/execute-ClFYvmp9.js +0 -211
- package/dist/runtime/driver.d.ts +0 -26
- package/dist/runtime/driver.js +0 -334
- package/dist/state-By7WU_ks.js +0 -472
- package/dist/store-t-74rsM_.d.ts +0 -48
- package/dist/types-Bcje4dLV.d.ts +0 -136
- package/dist/vite-BX6_KiRw.js +0 -1218
- package/dist/wait-until-CR-JjIOb.js +0 -23
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,72 +1,192 @@
|
|
|
1
1
|
# @vite-hub/schedule
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<img alt="Schedule" src="https://img.shields.io/badge/Schedule-cron%20runtime-0284c7?style=flat-square">
|
|
8
|
-
</p>
|
|
3
|
+
[](https://npmx.dev/package/@vite-hub/schedule)
|
|
4
|
+
[](https://npmx.dev/package/@vite-hub/schedule)
|
|
5
|
+
[](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
|
|
6
|
+
[](https://vitehub.dev/docs)
|
|
9
7
|
|
|
10
|
-
`@vite-hub/schedule`
|
|
8
|
+
`@vite-hub/schedule` discovers recurring work, generates cron output for supported hosts, and manages recurring schedules that an application creates while it runs.
|
|
11
9
|
|
|
12
|
-
##
|
|
10
|
+
## Choose the package
|
|
11
|
+
|
|
12
|
+
Install `vite-hub` for an application. It includes Schedule and exposes application imports under `vite-hub/schedule`.
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pnpm add vite-hub
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Enable Schedule with the framework integration and import application helpers from its feature path:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// vite.config.ts
|
|
22
|
+
import { vitehub } from "vite-hub";
|
|
23
|
+
import { defineConfig } from "vite";
|
|
24
|
+
|
|
25
|
+
export default defineConfig({
|
|
26
|
+
plugins: [vitehub({ preset: "cloudflare", schedule: true })],
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { defineSchedule } from "vite-hub/schedule";
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Install the owner package directly when a library or custom integration needs Schedule without the framework distribution.
|
|
13
35
|
|
|
14
36
|
```sh
|
|
15
37
|
pnpm add @vite-hub/schedule
|
|
16
38
|
```
|
|
17
39
|
|
|
18
|
-
Add `@vite-hub/kv` when using the default KV-backed stores or the generated Process Runtime. Static
|
|
40
|
+
Direct integrations use `@vite-hub/schedule`, `@vite-hub/schedule/runtime`, and `@vite-hub/schedule/vite`. Add Vite when the project uses `hubSchedule()`. Add `@vite-hub/kv` when using the default KV-backed stores or the generated Process Runtime. Static Schedule Definitions, memory stores, and custom `ScheduleKVStorage` implementations do not require KV.
|
|
41
|
+
|
|
42
|
+
Both packages require Node.js 24.15 or newer.
|
|
19
43
|
|
|
20
|
-
##
|
|
44
|
+
## Choose the schedule kind
|
|
45
|
+
|
|
46
|
+
| Kind | Create it with | Use it when |
|
|
47
|
+
| -------------------------- | ---------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
48
|
+
| Static Schedule Definition | `defineSchedule()` in a discovered source file | The cron is part of the deployment and can produce host Provider Output. |
|
|
49
|
+
| Schedule Target | `defineScheduleTarget()` in a discovered source file | Runtime Schedules need a named handler with no build-time cron. A target never produces static cron output. |
|
|
50
|
+
| Runtime Schedule | `schedules.create()` in server code | The application must create, update, pause, or delete a recurring schedule while it runs. |
|
|
51
|
+
|
|
52
|
+
A Runtime Schedule must name a Schedule Target. A Static Schedule Definition can also become a target when it sets `allowRuntimeSchedules: true`.
|
|
53
|
+
|
|
54
|
+
## Run one occurrence
|
|
55
|
+
|
|
56
|
+
This smoke test uses the direct owner-package import. If the application installed `vite-hub`, use `vite-hub/schedule` and `vite-hub/schedule/runtime`. It defines a Static Schedule and executes one fixed occurrence without a Vite config or hosted scheduler.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { defineSchedule } from "@vite-hub/schedule";
|
|
60
|
+
import { executeStaticSchedule } from "@vite-hub/schedule/runtime";
|
|
61
|
+
|
|
62
|
+
const dailyReport = defineSchedule({
|
|
63
|
+
cron: "0 8 * * *",
|
|
64
|
+
handler({ scheduledAt }) {
|
|
65
|
+
console.log(`Report scheduled for ${scheduledAt.toISOString()}`);
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const run = await executeStaticSchedule({
|
|
70
|
+
cron: dailyReport.cron,
|
|
71
|
+
definition: dailyReport,
|
|
72
|
+
name: "daily-report",
|
|
73
|
+
scheduledAt: new Date("2026-08-27T08:00:00.000Z"),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log(run.status);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```txt
|
|
80
|
+
Report scheduled for 2026-08-27T08:00:00.000Z
|
|
81
|
+
succeeded
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The example uses the default in-memory Schedule Run store. It proves the handler and run bookkeeping, but it does not install a recurring wake or generate Provider Output.
|
|
85
|
+
|
|
86
|
+
## Discover a static schedule
|
|
87
|
+
|
|
88
|
+
Register the direct owner-package integration in Vite.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
// vite.config.ts
|
|
92
|
+
import { hubSchedule } from "@vite-hub/schedule/vite";
|
|
93
|
+
import { defineConfig } from "vite";
|
|
94
|
+
|
|
95
|
+
export default defineConfig({
|
|
96
|
+
plugins: [hubSchedule()],
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Then export a definition from `server/schedules/<name>.ts` or `src/<name>.schedule.ts`.
|
|
21
101
|
|
|
22
102
|
```ts
|
|
23
103
|
// server/schedules/daily-report.ts
|
|
24
|
-
import { defineSchedule } from "@vite-hub/schedule"
|
|
104
|
+
import { defineSchedule } from "@vite-hub/schedule";
|
|
25
105
|
|
|
26
106
|
export default defineSchedule({
|
|
27
107
|
cron: "0 8 * * *",
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
108
|
+
async handler({ scheduledAt, waitUntil }) {
|
|
109
|
+
await sendDailyReport(scheduledAt);
|
|
110
|
+
waitUntil(recordDelivery());
|
|
31
111
|
},
|
|
32
|
-
})
|
|
112
|
+
});
|
|
33
113
|
```
|
|
34
114
|
|
|
115
|
+
Static Schedule Definitions use five-field UTC cron expressions. They cannot set `timeZone`. The integration can generate host-specific output for Cloudflare Cron Triggers, Vercel Cron Jobs, Netlify Scheduled Functions, standalone `Deno.cron`, and Nitro's Cloudflare schedule hook. 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.
|
|
116
|
+
|
|
117
|
+
Applications that use the framework distribution register Schedule through `vitehub({ preset, schedule: true })` and import the definition helper from `vite-hub/schedule`. The Deno framework preset currently rejects Schedule because standalone Deno cron output sits outside its generated Nitro entrypoint. Use the direct Schedule integration for that output.
|
|
118
|
+
|
|
119
|
+
Direct Nuxt projects can register `@vite-hub/schedule/nuxt` instead of `hubSchedule()`. The module installs the Vite integration and merges Schedule output into Nitro config.
|
|
120
|
+
|
|
121
|
+
## Create a Runtime Schedule
|
|
122
|
+
|
|
123
|
+
Define a cronless target for work that runs only through Runtime Schedules.
|
|
124
|
+
|
|
35
125
|
```ts
|
|
36
126
|
// server/schedules/report.ts
|
|
37
|
-
import { defineScheduleTarget } from "@vite-hub/schedule"
|
|
127
|
+
import { defineScheduleTarget } from "@vite-hub/schedule";
|
|
38
128
|
|
|
39
129
|
export default defineScheduleTarget<{ prompt: string }>({
|
|
40
|
-
|
|
41
|
-
if (input) await generateReport(input.prompt)
|
|
130
|
+
async handler({ input }) {
|
|
131
|
+
if (input) await generateReport(input.prompt);
|
|
42
132
|
},
|
|
43
|
-
})
|
|
133
|
+
});
|
|
44
134
|
```
|
|
45
135
|
|
|
136
|
+
Before creating the recurring record, install the Schedule runtime so it can load the discovered target registry and reconcile stored schedules. A custom host calls `installScheduleRuntime()` from `@vite-hub/schedule/runtime/driver` with its wake driver. A generated Process Runtime does this during application startup.
|
|
137
|
+
|
|
138
|
+
After runtime installation completes, create the recurring record from server code.
|
|
139
|
+
|
|
46
140
|
```ts
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
})
|
|
141
|
+
import { schedules } from "@vite-hub/schedule/runtime";
|
|
142
|
+
|
|
143
|
+
const report = await schedules.create({
|
|
144
|
+
cron: "30 8 * * 1-5",
|
|
145
|
+
id: "weekday-report",
|
|
146
|
+
input: { prompt: "Summarize yesterday" },
|
|
147
|
+
target: "report",
|
|
148
|
+
timeZone: "Europe/Copenhagen",
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
console.log(report.id);
|
|
59
152
|
```
|
|
60
153
|
|
|
61
|
-
|
|
154
|
+
The installed runtime can supply a native wake driver, or one long-lived process can install `createProcessScheduleWakeDriver()` from `@vite-hub/schedule/runtime/process`.
|
|
155
|
+
|
|
156
|
+
Static provider cron output does not automatically wake Runtime Schedules. Provider-backed Runtime Schedules need a host-owned wake driver. Request-scoped and serverless hosts must not use the Process Runtime because the process may stop between requests.
|
|
157
|
+
|
|
158
|
+
## Understand time zones
|
|
159
|
+
|
|
160
|
+
Static Schedule Definitions and their Provider Output always use UTC. Runtime Schedules use UTC when `timeZone` is absent and accept IANA time-zone names when the cron must follow local clock time.
|
|
161
|
+
|
|
162
|
+
Omitting `timeZone` during an update preserves the stored zone. Set it to `UTC` to return to UTC evaluation. Numeric offsets such as `+01:00` are rejected. During a daylight-saving gap, ViteHub skips a local time that does not exist. During an overlap, both distinct instants that share the repeated local time are due.
|
|
163
|
+
|
|
164
|
+
## Choose storage and wake ownership
|
|
165
|
+
|
|
166
|
+
Memory stores are the default for direct calls. They are process-local and lose Runtime Schedules and Schedule Run history on restart. Use `createKVRuntimeScheduleStore({ kvStore })` and `createKVScheduleRunStore({ kvStore })` when those records must survive a restart. Both factories require an explicit `ScheduleKVStorage`. Static schedules, memory stores, and custom storage do not require `@vite-hub/kv`.
|
|
167
|
+
|
|
168
|
+
To use ViteHub KV, install `@vite-hub/kv` and import the adapter explicitly:
|
|
62
169
|
|
|
63
170
|
```ts
|
|
64
|
-
|
|
65
|
-
import {
|
|
66
|
-
|
|
171
|
+
import { createKVRuntimeScheduleStore, createKVScheduleRunStore } from "@vite-hub/schedule/runtime"
|
|
172
|
+
import { scheduleKVStorage } from "@vite-hub/schedule/runtime/kv"
|
|
173
|
+
|
|
174
|
+
const runtimeScheduleStore = createKVRuntimeScheduleStore({ kvStore: scheduleKVStorage })
|
|
175
|
+
const scheduleRunStore = createKVScheduleRunStore({ kvStore: scheduleKVStorage })
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Migration: replace factory calls without `kvStore` with the explicit adapter shown above. Generated Process Runtime wiring selects this adapter automatically. Applications using the framework can import it from `vite-hub/schedule/runtime/kv`.
|
|
179
|
+
|
|
180
|
+
The generated Process Runtime creates both stores through the default KV store configured by `hubKv()`. It scans inside the Node.js process and runs discovered Static Schedule Definitions with stored Runtime Schedules. Configure it only for one long-lived replica:
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
import { hubKv } from "@vite-hub/kv/vite";
|
|
184
|
+
import { hubSchedule } from "@vite-hub/schedule/vite";
|
|
185
|
+
import { defineConfig } from "vite";
|
|
67
186
|
|
|
68
187
|
export default defineConfig({
|
|
69
188
|
plugins: [
|
|
189
|
+
hubKv(),
|
|
70
190
|
hubSchedule({
|
|
71
191
|
runtime: {
|
|
72
192
|
driver: "process",
|
|
@@ -74,53 +194,67 @@ export default defineConfig({
|
|
|
74
194
|
},
|
|
75
195
|
}),
|
|
76
196
|
],
|
|
77
|
-
})
|
|
197
|
+
});
|
|
78
198
|
```
|
|
79
199
|
|
|
80
|
-
|
|
200
|
+
Its defaults are prefix `vitehub:schedule`, scan interval `60_000` milliseconds, and concurrency `1`. The interval cannot exceed one minute. `concurrency` limits wake delivery only inside that process. The KV run store records occurrences but does not provide distributed leader election or locking, so multiple replicas can execute the same work. A stopped process does not backfill minutes that it missed.
|
|
81
201
|
|
|
82
|
-
|
|
202
|
+
With the Process Runtime, the default `providerOutput: "auto"` emits no host Provider Output, so the process owns Static Schedule wakes. Set `providerOutput: "standalone"` or `"nitro"` to move Static Schedule wakes to that Provider Output while the process continues to run Runtime Schedules. `providerOutput: false` explicitly records the same wake ownership as `"auto"` in this configuration.
|
|
83
203
|
|
|
84
|
-
|
|
204
|
+
`installScheduleRuntime()` returns only after its driver reconciles the complete stored snapshot, including disabled Runtime Schedules. Later creates, updates, and deletes persist first and reconcile one at a time. If host reconciliation fails, ViteHub restores the previous stored record and rejects the change.
|
|
85
205
|
|
|
86
|
-
|
|
206
|
+
When a custom host installs a wake driver, call and await `controller.close()` during shutdown. Closing stops new wakes, drains active wakes and `waitUntil()` work, and releases driver resources. It does not delete Schedule Definitions, Runtime Schedules, or run history. The generated Nitro Process Runtime registers the same close operation with ViteHub shutdown, so it runs on a stop signal before the server closes HTTP, or when Nitro closes. See [graceful shutdown](../runtime/README.md).
|
|
87
207
|
|
|
88
|
-
|
|
208
|
+
## Inspect Runtime Schedules
|
|
89
209
|
|
|
90
|
-
|
|
210
|
+
`hubSchedule()` contributes the `schedule.runs`, `schedule.attempts`, and `schedule.run` operations. They are the `vitehub schedule runs <id> [--limit <n>]`, `attempts <runId>`, and `run <name>` 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. The operations import from `@vite-hub/schedule/operations`.
|
|
91
211
|
|
|
92
|
-
|
|
93
|
-
import scheduleRegistry from "#vitehub/schedule/registry"
|
|
94
|
-
import { executeCloudflareStaticSchedules } from "@vite-hub/schedule/runtime/static"
|
|
212
|
+
Set `manual: true` on a Static Schedule Definition to allow an on-demand run, then invoke it with `vitehub schedule run <name>`. The name is the discovered schedule file name. Add `--url <app-url>` with the Console credentials to run it on a deployment that enables `console.invoke`. A CI job can post a signed dispatch (`vitehub secret derive vitehub:dispatch`) to `/_vitehub/schedules/run` instead.
|
|
95
213
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
214
|
+
Discovery reads `manual` and `allowRuntimeSchedules` as literal booleans from directly exported Definitions. Use identifier keys or quoted keys without escape sequences. Spreads, computed keys, escaped keys, and metadata getters or methods fail with the source file and line.
|
|
215
|
+
|
|
216
|
+
The Console Schedules section is a record table. Build-time records list Schedule Definitions. `readScheduleConsoleRecords()` from `@vite-hub/schedule/runtime/console` adds Runtime Schedules with enabled state, next run, last run, and run history on each request. The Console is read-only. A Runtime Schedule with `console: { enabled: false }` is hidden there. The CLI and the Console redact credentials in Schedule input and error messages.
|
|
217
|
+
|
|
218
|
+
## Import runtime helpers
|
|
219
|
+
|
|
220
|
+
The main `@vite-hub/schedule` entry exports `defineSchedule`, `defineScheduleTarget`, `schedules`, `validateRuntimeScheduleCron`, and public types. Import execution, storage, and runtime state helpers from `@vite-hub/schedule/runtime`. Import `discoverScheduleDefinitions` from `@vite-hub/schedule/vite` when writing a build integration. Applications use `vite-hub/schedule` and `vite-hub/schedule/runtime`.
|
|
221
|
+
|
|
222
|
+
Static Schedule execution logs each failed handler as `[vitehub:schedule] Schedule "<name>" failed` with the message, stack, status, and cause chain. The other schedules on the same cron still finish. The run rejects with the error, or with an `AggregateError` when several failed.
|
|
223
|
+
|
|
224
|
+
Runtime execution helpers accept `captureHandlerFailure: true` to return the persisted failed run after a handler error. Pre-execution guards, including disabled schedules, still throw.
|
|
225
|
+
Manual calls reject an existing disabled Runtime Schedule even when the same occurrence has a saved run. Provider wakes acknowledge saved occurrences after disablement without another handler attempt. A new provider occurrence still requires an enabled schedule.
|
|
226
|
+
|
|
227
|
+
This is a breaking import change. Move existing execution, store, and state helper imports to `/runtime`, and discovery imports to `/vite`. Helper behavior is unchanged. The main entry no longer loads file discovery or its build dependencies.
|
|
228
|
+
|
|
229
|
+
## Documentation and support
|
|
230
|
+
|
|
231
|
+
- Read the [Schedule guide](https://vitehub.dev/docs/schedule) for every public import, Runtime Helper, store, wake driver, and Vite option.
|
|
232
|
+
- Check [Provider Output](https://vitehub.dev/docs/reference/provider-output) for generated files and deployment inspection.
|
|
233
|
+
- Check [runtime and host support](https://vitehub.dev/docs/frameworks-hosts/support-matrix) for current proof and host qualifications.
|
|
234
|
+
- Report package problems in the [ViteHub issue tracker](https://github.com/vite-hub/vitehub/issues).
|
|
102
235
|
|
|
103
236
|
Cron parsing uses [`cron-schedule`](https://github.com/P4sca1/cron-schedule).
|
|
104
237
|
|
|
105
|
-
## Runtime Wake Drivers
|
|
106
238
|
|
|
107
|
-
|
|
239
|
+
## Definition-owned target inputs
|
|
108
240
|
|
|
109
|
-
|
|
110
|
-
import { installScheduleRuntime } from "@vite-hub/schedule/runtime/driver"
|
|
241
|
+
The Vite Integration writes `.vitehub/schedule.d.ts`. Include it in your TypeScript project. The Nuxt Integration includes it automatically. The generated `ScheduleTargetRegistry` maps eligible names to their definitions. `schedules.create()` checks input against the selected target:
|
|
111
242
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
243
|
+
```ts
|
|
244
|
+
const record = await schedules.create({
|
|
245
|
+
target: "daily-report",
|
|
246
|
+
cron: "0 9 * * *",
|
|
247
|
+
input: { prompt: "Summarize yesterday" },
|
|
117
248
|
})
|
|
249
|
+
await schedules.update(record.id, {
|
|
250
|
+
target: "daily-report",
|
|
251
|
+
input: { prompt: "Summarize this week" },
|
|
252
|
+
})
|
|
253
|
+
await schedules.update(record.id, { enabled: false })
|
|
118
254
|
```
|
|
119
255
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
Long-running hosts can use `createProcessScheduleWakeDriver()` from `@vite-hub/schedule/runtime/process` when they install the runtime directly. It keeps wake registration inside the current process; it does not install cron, systemd, or another operating-system scheduler.
|
|
256
|
+
When an update changes `input`, also supply `target`. When an update changes `target`, supply the new input or `input: undefined` to clear it. An ID alone does not identify a definition type. Stored records can outlive a deployment, so `get()`, `list()`, and `update()` return unknown input. Handler input remains optional; targets must handle records with no input.
|
|
123
257
|
|
|
124
|
-
`
|
|
258
|
+
Use `schedules.dynamic.create()` and `schedules.dynamic.update()` when names or stored input come from external data. The dynamic methods validate target eligibility and Schedule fields. They do not validate a target's business input. Validate that data in the application and again in a target that reads durable records.
|
|
125
259
|
|
|
126
|
-
|
|
260
|
+
This is a breaking change: include the generated declarations for typed application calls, and move operational calls with unknown names to `schedules.dynamic`. There is no permissive string overload on typed creation.
|