ENF News Bot
Automated News Bot
- Joined
- Apr 15, 2022
- Messages
- 2,591
A Worker can now call the Workflows it declares in the
Each Workflow is keyed by class name, and has the same API as a Workflow binding:
src/index.jsjs
src/index.tsts
A
In Vitest,
For more information, refer to Call a Workflow through
Continue reading...
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.jsjs
Code:
export default {
async fetch(request, env, ctx) {
const instance = await ctx.exports.MyWorkflow.create({
params: { name: "World" },
});
return Response.json({ id: instance.id });
},
};
Code:
export 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. You can move a Workflow from a binding to an export without losing its instances.wrangler dev, the Cloudflare Vite plugin, and the Workers Vitest integration run Workflows on ctx.exports locally. Local development requires Wrangler 4.142.0, @cloudflare/vite-plugin 1.61.0, or @cloudflare/vitest-plugin 1.3.0 or above.In Vitest,
introspectWorkflow() and introspectWorkflowInstance() still need a Workflow binding. To introspect a Workflow declared in exports, add a test-only binding to it.For more information, refer to Call a Workflow through
ctx.exports.Continue reading...