Overview
getRun() retrieves a Run object for an existing workflow execution, allowing you to check status, read results, access streams, and control execution.
Usage
Signature
string
required
The workflow run ID (format:
wrun_{ulid})Run<TResult> - A Run instance for interacting with the workflow
Run Class
TheRun class provides methods and properties for workflow interaction:
Properties
string
The unique identifier for this workflow run
Promise<WorkflowRunStatus>
Current status:
'pending', 'running', 'completed', 'failed', or 'cancelled'Promise<TResult>
The workflow’s return value. Polls until completion.Throws:
WorkflowRunFailedErrorif the workflow failedWorkflowRunCancelledErrorif the workflow was cancelled
Promise<string>
The name of the workflow function
Promise<Date>
Timestamp when the workflow run was created
Promise<Date | undefined>
Timestamp when execution started, or
undefined if not started yetPromise<Date | undefined>
Timestamp when execution completed, or
undefined if not completed yetReadableStream
The default readable stream for this workflow. Reads chunks written via
getWritable().Methods
getReadable()
Get a readable stream for this workflow run.WorkflowReadableStreamOptions
wakeUp()
Interrupt pendingsleep() calls. See Run.wakeUp().
cancel()
Cancel the workflow execution.Examples
Check Status
Get Return Value
Stream Results
Multiple Streams
Cancel Workflow
Workflow Metadata
Resume from Stream Position
API Route Handler
Streaming Response
Poll for Completion
Error Handling
WorkflowRunFailedError
WorkflowRunCancelledError
WorkflowRunNotFoundError
Type Safety
Best Practices
-
Type the result: Use
getRun<TResult>()for type-safe return values - Handle all error cases: Check for failed, cancelled, and not-found errors
- Use streams for real-time updates: Don’t poll status, use streams instead
- Store run IDs: Persist run IDs in your database for later retrieval
- Check status before actions: Verify workflow state before cancel/wakeUp operations
- Clean up readers: Always release stream readers when done