@@ -43,25 +43,34 @@ A workflow consists of:
4343
4444## Running a Workflow
4545
46- Start a workflow by calling ` .run() ` :
46+ Start a workflow by calling ` ow.runWorkflow() ` with the workflow's ` spec ` :
4747
4848``` ts
49+ import { ow } from " ./openworkflow/client" ;
4950import { sendWelcomeEmail } from " ./workflows/send-welcome-email" ;
5051
51- const handle = await sendWelcomeEmail .run ({ userId: " user_123" });
52+ const handle = await ow .runWorkflow (sendWelcomeEmail .spec , {
53+ userId: " user_123" ,
54+ });
5255```
5356
54- The ` run ()` method returns a handle immediately. The actual workflow execution
57+ ` ow.runWorkflow ()` returns a handle immediately. The actual workflow execution
5558happens in a worker process. This lets your application continue without waiting
5659for the workflow to complete.
5760
61+ <Note >
62+ If you define a workflow with ` ow.defineWorkflow(...) ` instead, it returns a
63+ runnable workflow that supports ` .run(...) ` directly.
64+ </Note >
65+
5866### Scheduling a Workflow Run
5967
6068You can schedule a workflow run for a specific time by passing ` availableAt ` :
6169
6270``` ts
6371const runAt = new Date (" 2026-02-05T15:00:00.000Z" );
64- const handle = await sendWelcomeEmail .run (
72+ const handle = await ow .runWorkflow (
73+ sendWelcomeEmail .spec ,
6574 { userId: " user_123" },
6675 { availableAt: runAt },
6776);
@@ -71,7 +80,8 @@ You can also pass a duration string using the same [duration
7180format] ( /docs/sleeping#duration-formats ) as ` step.sleep ` :
7281
7382``` ts
74- const handle = await sendWelcomeEmail .run (
83+ const handle = await ow .runWorkflow (
84+ sendWelcomeEmail .spec ,
7585 { userId: " user_123" },
7686 { availableAt: " 5m" },
7787);
@@ -85,7 +95,9 @@ it. If `availableAt` is in the past, the run is immediately available.
8595If you need to wait for a workflow to complete, use ` .result() ` on the handle:
8696
8797``` ts
88- const handle = await sendWelcomeEmail .run ({ userId: " user_123" });
98+ const handle = await ow .runWorkflow (sendWelcomeEmail .spec , {
99+ userId: " user_123" ,
100+ });
89101
90102// Wait for completion (polls the database)
91103const result = await handle .result ();
@@ -183,7 +195,7 @@ The workflow function receives an object with three properties:
183195
184196| Parameter | Type | Description |
185197| --------- | ---------------- | ------------------------------------------------- |
186- | ` input ` | Generic | The input data passed to ` workflow.run() ` |
198+ | ` input ` | Generic | The input data passed when starting the workflow |
187199| ` step ` | ` StepApi ` | API for defining steps (` step.run ` , ` step.sleep ` ) |
188200| ` version ` | ` string \| null ` | The workflow version, if specified |
189201
0 commit comments