createBatch() now accepts an options object that creates up to 100 Workflow instances in one call. The result lists the created instances and explains why any others were not created. To use this form in local development and get its types from wrangler types, use Wrangler 4.148.0 or later.
To create instances that share the same options, pass count. Each instance receives a generated ID:
const result = await env.MY_WORKFLOW.createBatch({
count: 10,
params: { report: "daily" },
});
const result = await env.MY_WORKFLOW.createBatch({
count: 10,
params: { report: "daily" },
});
To give each instance its own ID or options, pass instances:
const { created, errors } = await env.MY_WORKFLOW.createBatch({
instances: [
{ id: "order-1", params: { orderId: 1 } },
{ id: "order-2", params: { orderId: 2 } },
],
});
for (const error of errors) {
console.log(error.index, error.id, error.code, error.message);
}
const { created, errors } = await env.MY_WORKFLOW.createBatch({
instances: [
{ id: "order-1", params: { orderId: 1 } },
{ id: "order-2", params: { orderId: 2 } },
],
});
for (const error of errors) {
console.log(error.index, error.id, error.code, error.message);
}
created contains the created instances. errors contains each entry that was not created, identified by its position in the input. IDs that already exist and IDs repeated within the batch are reported as errors instead of being skipped silently.
Passing an array to createBatch() is deprecated. Existing code that uses the array form continues to work.
For more information, refer to createBatch.
Source: Cloudflare


