start()
Start/enqueue a new workflow run.
import { start } from 'workflow/api';
import { myWorkflow } from './workflows/my-workflow';
const run = await start(myWorkflow); API Signature
Parameters
This function has multiple signatures.
Signature 1
| Name | Type | Description |
|---|---|---|
workflow | WorkflowFunction<TArgs, TResult> | WorkflowMetadata | The imported workflow function to start. |
args | TArgs | The arguments to pass to the workflow (optional). |
options | StartOptions | The options for the workflow run (optional). |
Signature 2
| Name | Type | Description |
|---|---|---|
workflow | WorkflowMetadata | WorkflowFunction<[], TResult> | |
options | StartOptions |
StartOptions
| Name | Type | Description |
|---|---|---|
deploymentId | string | The deployment ID to use for the workflow run. |
Returns
Returns a Run object:
| Name | Type | Description |
|---|---|---|
runId | string | The ID of the workflow run. |
cancel | () => Promise<void> | Cancels the workflow run. |
status | Promise<"pending" | "running" | "completed" | "failed" | "paused" | "cancelled"> | The status of the workflow run. |
returnValue | Promise<TResult> | The return value of the workflow run. Polls the workflow return value until it is completed. |
workflowName | Promise<string> | The name of the workflow. |
createdAt | Promise<Date> | The timestamp when the workflow run was created. |
startedAt | Promise<Date | undefined> | The timestamp when the workflow run started execution. Returns undefined if the workflow has not started yet. |
completedAt | Promise<Date | undefined> | The timestamp when the workflow run completed. Returns undefined if the workflow has not completed yet. |
readable | ReadableStream<any> | The readable stream of the workflow run. |
getReadable | <R = any>(options?: WorkflowReadableStreamOptions | undefined) => ReadableStream<R> | Retrieves the workflow run's default readable stream, which reads chunks written to the corresponding writable stream getWritable . |
Good to Know
- The
start()function is used in runtime/non-workflow contexts to programmatically trigger workflow executions. - This is different from calling workflow functions directly, which is the typical pattern in Next.js applications.
- The function returns immediately after enqueuing the workflow - it doesn't wait for the workflow to complete.
- All arguments must be serializable.
Examples
With Arguments
import { start } from 'workflow/api';
import { userSignupWorkflow } from './workflows/user-signup';
const run = await start(userSignupWorkflow, ['user@example.com']); With StartOptions
import { start } from 'workflow/api';
import { myWorkflow } from './workflows/my-workflow';
const run = await start(myWorkflow, ['arg1', 'arg2'], {
deploymentId: 'custom-deployment-id'
});