Skip to content

Commit f718da1

Browse files
Update docs to use ow.runWorkflow (#286)
1 parent d828d64 commit f718da1

7 files changed

Lines changed: 39 additions & 23 deletions

File tree

packages/docs/docs/advanced-patterns.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ TypeScript will catch type errors at compile time, preventing runtime issues.
111111
Wait for a workflow to complete and get its result:
112112

113113
```ts
114-
const run = await myWorkflow.run({ data: "..." });
114+
const run = await ow.runWorkflow(myWorkflow.spec, { data: "..." });
115115

116116
// Wait for the workflow to finish (polls the database)
117117
const result = await run.result();
@@ -129,7 +129,7 @@ Cancel a workflow that is pending, running, or sleeping to prevent it from
129129
continuing:
130130

131131
```ts
132-
const handle = await myWorkflow.run({ data: "..." });
132+
const handle = await ow.runWorkflow(myWorkflow.spec, { data: "..." });
133133

134134
// Cancel the workflow
135135
await handle.cancel();
@@ -191,7 +191,7 @@ const summarizeDoc = defineWorkflow(
191191
);
192192

193193
// Throws before enqueueing the workflow because the input isn't a URL
194-
await summarizeDoc.run({ docUrl: "not-a-url" });
194+
await ow.runWorkflow(summarizeDoc.spec, { docUrl: "not-a-url" });
195195
```
196196

197197
Any validator function works as long as it throws on invalid data. This supports

packages/docs/docs/canceling.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ You can cancel workflow runs that are pending, running, or sleeping.
1010
Use the `cancel()` method on a workflow run handle:
1111

1212
```ts
13+
import { ow } from "./openworkflow/client";
1314
import { defineWorkflow } from "openworkflow";
1415

1516
const longRunning = defineWorkflow(
@@ -21,7 +22,7 @@ const longRunning = defineWorkflow(
2122
);
2223

2324
// Start the workflow
24-
const handle = await longRunning.run();
25+
const handle = await ow.runWorkflow(longRunning.spec);
2526

2627
// Cancel it before it completes
2728
await handle.cancel();
@@ -67,7 +68,7 @@ no new steps will run on the next poll.
6768
After calling `cancel()`, you can verify the status:
6869

6970
```ts
70-
const handle = await workflow.run();
71+
const handle = await ow.runWorkflow(workflow.spec);
7172
await handle.cancel();
7273

7374
// Waiting for result on a canceled workflow throws

packages/docs/docs/overview.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Your application enqueues workflow runs. Workers pick them up. The backend
2121

2222
When a run starts:
2323

24-
1. Your app calls `workflow.run()`, creating a `pending` run in the database
24+
1. Your app enqueues a run (for example, with `ow.runWorkflow(workflow.spec,
25+
input)`), creating a `pending` run in the database
2526
2. A worker claims the run and marks it `running`
2627
3. The worker replays workflow code from the beginning
2728
4. Completed steps return cached outputs; new steps execute and persist results

packages/docs/docs/quickstart.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ bun openworkflow/hello-world.run.ts
7474

7575
</CodeGroup>
7676

77-
This script calls `workflow.run()` to create a new workflow run in the database.
78-
The worker in your first terminal picks it up, executes each step, and marks it
79-
complete.
77+
This script calls `ow.runWorkflow(helloWorld.spec, {})` to create a new workflow
78+
run in the database. The worker in your first terminal picks it up, executes
79+
each step, and marks it complete.
8080

8181
<Note>
8282
The `hello-world.run.ts` file is a temporary helper for testing. In a real
83-
app, you'd call `workflow.run()` from your API routes, scripts, or other
84-
application code.
83+
app, you'd call `ow.runWorkflow(workflow.spec, input)` from your API routes,
84+
scripts, or other application code.
8585
</Note>
8686

8787
## 4. View workflows in the dashboard

packages/docs/docs/standard-schema.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ is even enqueued — preventing invalid data from entering your system.
1515
When you define a workflow, you can provide a `schema`. OpenWorkflow uses this
1616
schema to:
1717

18-
1. **Validate inputs at runtime**: When `workflow.run()` is called, the input is
19-
validated immediately. If validation fails, an error is thrown before the
20-
workflow is enqueued, preventing invalid data from entering your system.
18+
1. **Validate inputs at runtime**: When you start a run (for example, with
19+
`ow.runWorkflow(workflow.spec, input)`), the input is validated immediately.
20+
If validation fails, an error is thrown before the workflow is enqueued,
21+
preventing invalid data from entering your system.
2122
2. **Type Safety**: The `input` parameter in your workflow function is
2223
automatically typed based on your schema.
2324

@@ -141,10 +142,11 @@ When validation fails, OpenWorkflow throws a detailed error that includes
141142
information about what went wrong:
142143

143144
```ts
145+
import { ow } from "./openworkflow/client";
144146
import { sendEmail } from "./workflows/send-email";
145147

146148
try {
147-
await sendEmail.run({
149+
await ow.runWorkflow(sendEmail.spec, {
148150
to: "invalid-email", // Invalid email format
149151
subject: "", // Too short
150152
body: "Hello",

packages/docs/docs/type-safety.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ ow.implementWorkflow(emailSpec, async ({ input, step }) => {
115115
When you run a workflow, the handle is typed with the output:
116116

117117
```ts
118-
const handle = await processOrder.run({
118+
const handle = await ow.runWorkflow(processOrder.spec, {
119119
orderId: "123",
120120
customerId: "456",
121121
});

packages/docs/docs/workflows.mdx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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";
4950
import { 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
5558
happens in a worker process. This lets your application continue without waiting
5659
for 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

6068
You can schedule a workflow run for a specific time by passing `availableAt`:
6169

6270
```ts
6371
const 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
7180
format](/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.
8595
If 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)
91103
const 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

Comments
 (0)