Skip to main content

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})
Returns: Run<TResult> - A Run instance for interacting with the workflow

Run Class

The Run 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:
  • WorkflowRunFailedError if the workflow failed
  • WorkflowRunCancelledError if 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 yet
Promise<Date | undefined>
Timestamp when execution completed, or undefined if not completed yet
ReadableStream
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 pending sleep() 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

  1. Type the result: Use getRun<TResult>() for type-safe return values
  2. Handle all error cases: Check for failed, cancelled, and not-found errors
  3. Use streams for real-time updates: Don’t poll status, use streams instead
  4. Store run IDs: Persist run IDs in your database for later retrieval
  5. Check status before actions: Verify workflow state before cancel/wakeUp operations
  6. Clean up readers: Always release stream readers when done

See Also