Workflows, Workers - Call Workflows declared in `exports` through `ctx.exports`
From the publisher
A Worker can now call the Workflows it declares in the exports field of its Wrangler configuration through ctx.exports. You no longer need a workflows binding to call a Workflow from the Worker that defines it. Each Workflow is keyed by class name, and has the same API as a Workflow binding: src/index.jsjsexport default { async fetch(request, env, ctx) { const instance = await ctx.exports.MyWorkflow.create({ params: { name: "World" }, }); return Response.json({ id: instance.id }); }, }; src/index.tstsexport default { async fetch(request, env, ctx): Promise<Response> { const instance = await ctx.exports.MyWorkflow.create({ params: { name: "World" }, }); return Response.json({ id: instance.id }); }, } satisfies ExportedHandler<Env>; A workflows binding and a workflow export with the same name share their instances.
Source Cloudflare DevelopersCC BY 4.0 · Publisher excerpt shortened and converted to plain text. Original source license applies.
Read full article

