File tree 7 files changed +38
-0
lines changed
7 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " example-worker-app " : patch
3
+ " wrangler " : patch
4
+ ---
5
+
6
+ fix: add support for cron triggers in ` dev --local ` mode
7
+
8
+ Currently, I don't know if there is support for doing this in "remote" dev mode.
9
+
10
+ Resolves #737
Original file line number Diff line number Diff line change @@ -10,6 +10,18 @@ export default {
10
10
11
11
return new Response ( `${ request . url } ${ now ( ) } ` ) ;
12
12
} ,
13
+
14
+ /**
15
+ * Handle a scheduled event.
16
+ *
17
+ * If developing using `--local` mode, you can trigger this scheduled event via a CURL.
18
+ * E.g. `curl "http://localhost:8787/cdn-cgi/mf/scheduled"`.
19
+ * See the Miniflare docs: https://miniflare.dev/core/scheduled.
20
+ */
21
+ scheduled ( event , env , ctx ) {
22
+ ctx . waitUntil ( Promise . resolve ( event . scheduledTime ) ) ;
23
+ ctx . waitUntil ( Promise . resolve ( event . cron ) ) ;
24
+ } ,
13
25
} ;
14
26
15
27
// addEventListener("fetch", (event) => {
Original file line number Diff line number Diff line change
1
+ name = " example-worker-app"
2
+ compatibility_date = " 2022-03-31"
3
+
4
+ main = " src/index.js"
5
+
6
+ [triggers ]
7
+ crons = [" 1 * * * *" ]
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ export type DevProps = {
37
37
localProtocol : "https" | "http" ;
38
38
enableLocalPersistence : boolean ;
39
39
bindings : CfWorkerInit [ "bindings" ] ;
40
+ crons : Config [ "triggers" ] [ "crons" ] ;
40
41
public : undefined | string ;
41
42
assetPaths : undefined | AssetPaths ;
42
43
compatibilityDate : undefined | string ;
@@ -163,6 +164,7 @@ function DevSession(props: DevSessionProps) {
163
164
rules = { props . rules }
164
165
inspectorPort = { props . inspectorPort }
165
166
enableLocalPersistence = { props . enableLocalPersistence }
167
+ crons = { props . crons }
166
168
/>
167
169
) : (
168
170
< Remote
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ interface LocalProps {
27
27
rules : Config [ "rules" ] ;
28
28
inspectorPort : number ;
29
29
enableLocalPersistence : boolean ;
30
+ crons : Config [ "triggers" ] [ "crons" ] ;
30
31
}
31
32
32
33
export function Local ( props : LocalProps ) {
@@ -52,6 +53,7 @@ function useLocalWorker({
52
53
rules,
53
54
enableLocalPersistence,
54
55
ip,
56
+ crons,
55
57
} : LocalProps ) {
56
58
// TODO: pass vars via command line
57
59
const local = useRef < ReturnType < typeof spawn > > ( ) ;
@@ -150,6 +152,7 @@ function useLocalWorker({
150
152
dataBlobBindings,
151
153
sourceMap : true ,
152
154
logUnhandledRejections : true ,
155
+ crons,
153
156
} ;
154
157
155
158
// The path to the Miniflare CLI assumes that this file is being run from
@@ -247,6 +250,7 @@ function useLocalWorker({
247
250
bindings . wasm_modules ,
248
251
bindings . text_blobs ,
249
252
bindings . data_blobs ,
253
+ crons ,
250
254
] ) ;
251
255
return { inspectorUrl } ;
252
256
}
Original file line number Diff line number Diff line change @@ -927,6 +927,7 @@ export async function main(argv: string[]): Promise<void> {
927
927
r2_buckets : config . r2_buckets ,
928
928
unsafe : config . unsafe ?. bindings ,
929
929
} }
930
+ crons = { config . triggers . crons }
930
931
/>
931
932
) ;
932
933
await waitUntilExit ( ) ;
@@ -1310,6 +1311,7 @@ export async function main(argv: string[]): Promise<void> {
1310
1311
r2_buckets : config . r2_buckets ,
1311
1312
unsafe : config . unsafe ?. bindings ,
1312
1313
} }
1314
+ crons = { config . triggers . crons }
1313
1315
inspectorPort = { await getPort ( { port : 9229 } ) }
1314
1316
/>
1315
1317
) ;
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ async function main() {
26
26
try {
27
27
// Start Miniflare development server
28
28
await mf . startServer ( ) ;
29
+ await mf . startScheduler ( ) ;
29
30
} catch ( e ) {
30
31
mf . log . error ( e as Error ) ;
31
32
process . exitCode = 1 ;
You can’t perform that action at this time.
0 commit comments