Skip to content

Commit 34aa049

Browse files
Fix some typos (#17756)
* Fix some typos * Another one * And another one * Clean up spaces and tabs
1 parent c61a29b commit 34aa049

File tree

6 files changed

+37
-29
lines changed

6 files changed

+37
-29
lines changed

src/content/docs/workflows/build/events-and-parameters.mdx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,23 @@ Store state durably by returning it from your `step.do` callbacks.
2929

3030
```ts
3131
export default {
32-
async fetch(req: Request, env: Env) {
33-
let someEvent = { url: req.url, createdTimestamp: Date.now() }
34-
// Trigger our Workflow
35-
// Pass our event as the second parameter to the `create` method
36-
// on our Workflow binding.
37-
let instance = await env.MYWORKFLOW.create(await crypto.randomUUID(), someEvent);
38-
39-
return Response.json({
40-
id: instance.id,
41-
details: await instance.status(),
42-
});
43-
44-
return Response.json({ result });
45-
},
32+
async fetch(req: Request, env: Env) {
33+
let someEvent = { url: req.url, createdTimestamp: Date.now() }
34+
// Trigger our Workflow
35+
// Pass our event as the second parameter to the `create` method
36+
// on our Workflow binding.
37+
let instance = await env.MYWORKFLOW.create({
38+
id: await crypto.randomUUID(),
39+
params: someEvent
40+
});
41+
42+
return Response.json({
43+
id: instance.id,
44+
details: await instance.status(),
45+
});
46+
47+
return Response.json({ result });
48+
},
4649
};
4750
```
4851

src/content/docs/workflows/build/rules-of-workflows.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ check if they were already charged:
1919

2020
```ts
2121
export class MyWorkflow extends WorkflowEntrypoint {
22-
async run(event: WorkflowEvent, step: WorkflowStep) {
22+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
2323
const customer_id = 123456;
2424
// ✅ Good: Non-idempotent API/Binding calls are always done **after** checking if the operation is
2525
// still needed.
@@ -69,7 +69,7 @@ You can also think of it as a transaction, or a unit of work.
6969

7070
```ts
7171
export class MyWorkflow extends WorkflowEntrypoint {
72-
async run(event: WorkflowEvent, step: WorkflowStep) {
72+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
7373
// ✅ Good: Unrelated API/Binding calls are self-contained, so that in case one of them fails
7474
// it can retry them individually. It also has an extra advantage: you can control retry or
7575
// timeout policies for each granular step - you might not to want to overload http.cat in
@@ -94,7 +94,7 @@ Otherwise, your entire Workflow might not be as durable as you might think, and
9494

9595
```ts
9696
export class MyWorkflow extends WorkflowEntrypoint {
97-
async run(event: WorkflowEvent, step: WorkflowStep) {
97+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
9898
// 🔴 Bad: you're calling two seperate services from within the same step. This might cause
9999
// some extra calls to the first service in case the second one fails, and in some cases, makes
100100
// the step non-idempotent altogether
@@ -120,7 +120,7 @@ function getRandomInt(min, max) {
120120
}
121121

122122
export class MyWorkflow extends WorkflowEntrypoint {
123-
async run(event: WorkflowEvent, step: WorkflowStep) {
123+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
124124
// 🔴 Bad: `imageList` will be not persisted across engine's lifetimes. Which means that after hibernation,
125125
// `imageList` will be empty again, even though the following two steps have already ran.
126126
const imageList: string[] = [];
@@ -163,7 +163,7 @@ function getRandomInt(min, max) {
163163
}
164164

165165
export class MyWorkflow extends WorkflowEntrypoint {
166-
async run(event: WorkflowEvent, step: WorkflowStep) {
166+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
167167
// ✅ Good: imageList state is exclusively comprised of step returns - this means that in the event of
168168
// multiple engine lifetimes, imageList will be built accordingly
169169
const imageList: string[] = await Promise.all([
@@ -231,7 +231,7 @@ Dynamically naming a step will prevent it from being cached, and cause the step
231231
232232
```ts
233233
export class MyWorkflow extends WorkflowEntrypoint {
234-
async run(event: WorkflowEvent, step: WorkflowStep) {
234+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
235235
// 🔴 Bad: Dynamically naming the step prevents it from being cached
236236
// This will cause the step to be re-run if subsequent steps fail.
237237
await step.do(`step #1 running at: ${Date.now}`, async () => {

src/content/docs/workflows/build/sleeping-and-retrying.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ This can be useful when you detect a terminal (permanent) error from an upstream
9595
9696
```ts
9797
// Import the NonRetryableError definition
98-
import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent, NonRetryableError } from 'cloudflare:workers';
98+
import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent } from 'cloudflare:workers';
99+
import { NonRetryableError } from 'cloudflare:workflows';
99100
100101
// In your step code:
101102
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {

src/content/docs/workflows/build/trigger-workflows.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ To bind to a Workflow from your Workers code, you need to define a [binding](/wo
3434
```toml title="wrangler.toml"
3535
name = "workflows-tutorial"
3636
main = "src/index.ts"
37-
compatibility_date = "2024-10-15"
37+
compatibility_date = "2024-10-22"
3838

3939
[[workflows]]
4040
# The name of the Workflow
@@ -80,7 +80,7 @@ export default {
8080
// Else, create a new instance of our Workflow, passing in any (optional) params
8181
// and return the ID.
8282
const newId = await crypto.randomUUID();
83-
let instance = await env.MY_WORKFLOW.create(newId, {});
83+
let instance = await env.MY_WORKFLOW.create({ id: newId });
8484
return Response.json({
8585
id: instance.id,
8686
details: await instance.status(),

src/content/docs/workflows/build/workers-api.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ For example, to bind to a Workflow called `workflows-starter` and to make it ava
111111
#:schema node_modules/wrangler/config-schema.json
112112
name = "workflows-starter"
113113
main = "src/index.ts"
114-
compatibility_date = "2024-10-16"
114+
compatibility_date = "2024-10-22"
115115

116116
[[workflows]]
117117
# name of your workflow

src/content/docs/workflows/get-started/guide.mdx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ Open the `src/index.ts` file in your text editor. This file contains the followi
4949
// Import the Workflow definition
5050
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from "cloudflare:workers"
5151

52+
type Params = {}
53+
5254
// Create your own class that implements a Workflow
53-
export class MyWorkflow implements WorkflowEntrypoint {
55+
export class MyWorkflow extends WorkflowEntrypoint {
5456
// Define a run() method
55-
async run(event: WorkflowEvent, step: WorkflowStep) {
57+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
5658
// Define one or more steps that optionally return state.
5759
const state = await step.do('my first step', async () => {
5860
return {}
@@ -99,10 +101,12 @@ At its most basic, a step looks like this:
99101
// Import the Workflow definition
100102
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from "cloudflare:workers"
101103

104+
type Params = {}
105+
102106
// Create your own class that implements a Workflow
103-
export class MyWorkflow implements WorkflowEntrypoint {
107+
export class MyWorkflow extends WorkflowEntrypoint {
104108
// Define a run() method
105-
async run(event: WorkflowEvent, step: WorkflowStep) {
109+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
106110
// Define one or more steps that optionally return state.
107111
let state = step.do("my first step", async () => {
108112

@@ -150,7 +154,7 @@ Open the `wrangler.toml` file at the root of your `workflows-starter` folder, wh
150154
#:schema node_modules/wrangler/config-schema.json
151155
name = "workflows-starter"
152156
main = "src/index.ts"
153-
compatibility_date = "2024-10-23"
157+
compatibility_date = "2024-10-22"
154158

155159
[[workflows]]
156160
# name of your workflow

0 commit comments

Comments
 (0)