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> {
146146 handle = await this . env . WORKFLOW2 . get ( id ) ;
147147 } else if ( url . pathname === "/get3" ) {
148148 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" ) {
150158 handle = await this . env . WORKFLOW . get ( id ) ;
151159 }
152160
Original file line number Diff line number Diff line change @@ -257,6 +257,23 @@ describe("Workflows", () => {
257257 ) ;
258258 } ) ;
259259
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+
260277 it ( "should persist instances across lifetimes" , async ( { expect } ) => {
261278 await fetchJson ( `http://${ ip } :${ port } /create?workflowName=something` ) ;
262279
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ export class WorkflowBinding extends WorkerEntrypoint<Env> implements Workflow {
2828 const stubId = this . env . ENGINE . idFromName ( id ) ;
2929 const stub = this . env . ENGINE . get ( stubId ) ;
3030
31- void stub . init (
31+ const initPromise = stub . init (
3232 0 , // accountId: number,
3333 { } as DatabaseWorkflow , // workflow: DatabaseWorkflow,
3434 { } as DatabaseVersion , // version: DatabaseVersion,
@@ -40,6 +40,8 @@ export class WorkflowBinding extends WorkerEntrypoint<Env> implements Workflow {
4040 }
4141 ) ;
4242
43+ this . ctx . waitUntil ( initPromise ) ;
44+
4345 const handle = new WorkflowHandle ( id , stub ) ;
4446 return {
4547 id : id ,
@@ -55,7 +57,6 @@ export class WorkflowBinding extends WorkerEntrypoint<Env> implements Workflow {
5557 public async get ( id : string ) : Promise < WorkflowInstance > {
5658 const engineStubId = this . env . ENGINE . idFromName ( id ) ;
5759 const engineStub = this . env . ENGINE . get ( engineStubId ) ;
58-
5960 const handle = new WorkflowHandle ( id , engineStub ) ;
6061
6162 try {
You can’t perform that action at this time.
0 commit comments