File tree Expand file tree Collapse file tree 4 files changed +34
-3
lines changed
packages/workflows-shared/src Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @cloudflare/workflows-shared " : patch
3
+ ---
4
+
5
+ Workflows are now created if the Request gets redirected after creation
Original file line number Diff line number Diff line change @@ -146,7 +146,15 @@ export default class extends WorkerEntrypoint<Env> {
146
146
handle = await this . env . WORKFLOW2 . get ( id ) ;
147
147
} else if ( url . pathname === "/get3" ) {
148
148
handle = await this . env . WORKFLOW3 . get ( id ) ;
149
- } else {
149
+ } else if ( url . pathname === "/createWithRedirect" ) {
150
+ console . log ( "create with redirect called" ) ;
151
+ handle = await this . env . WORKFLOW . create ( ) ;
152
+
153
+ return Response . redirect (
154
+ new URL ( `/status?workflowName=${ handle . id } ` , url ) . toString ( ) ,
155
+ 302
156
+ ) ;
157
+ } else if ( url . pathname === "/status" ) {
150
158
handle = await this . env . WORKFLOW . get ( id ) ;
151
159
}
152
160
Original file line number Diff line number Diff line change @@ -257,6 +257,23 @@ describe("Workflows", () => {
257
257
) ;
258
258
} ) ;
259
259
260
+ it ( "should create an instance after immediate redirect" , async ( {
261
+ expect,
262
+ } ) => {
263
+ await expect ( fetchJson ( `http://${ ip } :${ port } /createWithRedirect` ) ) . resolves
264
+ . toMatchInlineSnapshot ( `
265
+ {
266
+ "__LOCAL_DEV_STEP_OUTPUTS": [
267
+ {
268
+ "output": "First step result",
269
+ },
270
+ ],
271
+ "output": null,
272
+ "status": "running",
273
+ }
274
+ ` ) ;
275
+ } ) ;
276
+
260
277
it ( "should persist instances across lifetimes" , async ( { expect } ) => {
261
278
await fetchJson ( `http://${ ip } :${ port } /create?workflowName=something` ) ;
262
279
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ export class WorkflowBinding extends WorkerEntrypoint<Env> implements Workflow {
28
28
const stubId = this . env . ENGINE . idFromName ( id ) ;
29
29
const stub = this . env . ENGINE . get ( stubId ) ;
30
30
31
- void stub . init (
31
+ const initPromise = stub . init (
32
32
0 , // accountId: number,
33
33
{ } as DatabaseWorkflow , // workflow: DatabaseWorkflow,
34
34
{ } as DatabaseVersion , // version: DatabaseVersion,
@@ -40,6 +40,8 @@ export class WorkflowBinding extends WorkerEntrypoint<Env> implements Workflow {
40
40
}
41
41
) ;
42
42
43
+ this . ctx . waitUntil ( initPromise ) ;
44
+
43
45
const handle = new WorkflowHandle ( id , stub ) ;
44
46
return {
45
47
id : id ,
@@ -55,7 +57,6 @@ export class WorkflowBinding extends WorkerEntrypoint<Env> implements Workflow {
55
57
public async get ( id : string ) : Promise < WorkflowInstance > {
56
58
const engineStubId = this . env . ENGINE . idFromName ( id ) ;
57
59
const engineStub = this . env . ENGINE . get ( engineStubId ) ;
58
-
59
60
const handle = new WorkflowHandle ( id , engineStub ) ;
60
61
61
62
try {
You can’t perform that action at this time.
0 commit comments