Skip to content

Commit a8de669

Browse files
elithrarOxyjun
andauthored
workflows: Apply suggestions from code review
Co-authored-by: Jun Lee <[email protected]>
1 parent 5ddce18 commit a8de669

File tree

1 file changed

+17
-21
lines changed
  • src/content/docs/workflows/get-started

1 file changed

+17
-21
lines changed

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

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ At the end of this guide, you should be able to author, deploy and debug your ow
3131

3232
## Prerequisites
3333

34-
To continue:
35-
36-
1. Sign up for a [Cloudflare account](https://dash.cloudflare.com/sign-up/workers-and-pages) if you have not already.
37-
2. Install [`npm`](https://docs.npmjs.com/getting-started).
38-
3. Install [`Node.js`](https://nodejs.org/en/). Use a Node version manager like [Volta](https://volta.sh/) or [nvm](https://github.com/nvm-sh/nvm) to avoid permission issues and change Node.js versions. [Wrangler](/workers/wrangler/install-and-update/) requires a Node version of `16.17.0` or later.
34+
<Render file="prereqs" product="workers" />
3935

4036
## 1. Define your Workflow
4137

@@ -83,7 +79,7 @@ A Workflow definition:
8379
2. Has at least one or more calls to `step.do` that encapsulates the logic of your Workflow.
8480
3. Allows steps to return (optional) state, allowing a Workflow to continue execution even if subsequent steps fail, without having to re-run all previous steps.
8581

86-
A single Worker application can contain multiple Workflow definitions, as long as each Workflow has a unique class name. This can be useful for code re-use or to define Workflows are related to each other conceptually.
82+
A single Worker application can contain multiple Workflow definitions, as long as each Workflow has a unique class name. This can be useful for code re-use or to define Workflows which are related to each other conceptually.
8783

8884
Each Workflow is otherwise entirely independent: a Worker that defines multiple Workflows is no different from a set of Workers that define one Workflow each.
8985

@@ -93,11 +89,11 @@ Each `step` in a Workflow is an independently retriable function.
9389

9490
A `step` is what makes a Workflow powerful, as you can encapsulate errors and persist state as your Workflow progresses from step to step, avoiding your application from having to start from scratch on failure and ultimately build more reliable applications.
9591

96-
* A step can execute code (`step.do`) or sleep a Workflow (`step.sleep`)
92+
* A step can execute code (`step.do`) or sleep a Workflow (`step.sleep`).
9793
* If a step fails (throws an exception), it will be automatically be retried based on your retry logic.
98-
* Ia step succeeds, any state it returns will be persisted within the Workflow.
94+
* If a step succeeds, any state it returns will be persisted within the Workflow.
9995

100-
At it's most basic, a step looks like this:
96+
At its most basic, a step looks like this:
10197

10298
```ts title="src/index.ts"
10399
// Import the Workflow definition
@@ -123,7 +119,7 @@ Each call to `step.do` accepts three arguments:
123119

124120
1. (Required) A step name, which identifies the step in logs and telemetry
125121
2. (Required) A callback function that contains the code to run for your step, and any state you want the Workflow to persist
126-
3. (Optional) A `StepConfig` that defines the retry configuration (max retries, delay, and backoff algorithm) for the step.
122+
3. (Optional) A `StepConfig` that defines the retry configuration (max retries, delay, and backoff algorithm) for the step
127123

128124
When trying to decide whether to break code up into more than one step, a good rule of thumb is to ask "do I want _all_ of this code to run again if just one part of it fails?". In many cases, you do _not_ want to repeatedly call an API if the following data processing stage fails, or if you get an error when attempting to send a completion or welcome email.
129125

@@ -134,13 +130,13 @@ For example, each of the below tasks is ideally encapsulated in its own step, so
134130
* Querying a D1 database or a database via [Hyperdrive](/hyperdrive/)
135131
* Calling a third-party API
136132

137-
If a subsequent step fails, your Workflow can retry from that step, using any state returned from a previous step. This can also help you avoid unnecessarily querying a database or calling an paid API repeatedly for data you've already fetched.
133+
If a subsequent step fails, your Workflow can retry from that step, using any state returned from a previous step. This can also help you avoid unnecessarily querying a database or calling an paid API repeatedly for data you have already fetched.
138134

139135
:::note
140136

141137
The term "Durable Execution" is widely used to describe this programming model.
142138

143-
"Durable" describes the ability of the program (application) to implicitly persist state without you having to write to an external store or serialize program state manual
139+
"Durable" describes the ability of the program (application) to implicitly persist state without you having to manually write to an external store or serialize program state.
144140

145141
:::
146142

@@ -170,7 +166,7 @@ script_name = "workflows-starter"
170166

171167
:::note
172168

173-
If you have changed the name of the Workflow in your wrangler commands, the JavaScript class name, or the name of the project you created, ensure that you update the values above to match.
169+
If you have changed the name of the Workflow in your Wrangler commands, the JavaScript class name, or the name of the project you created, ensure that you update the values above to match the changes.
174170

175171
:::
176172

@@ -336,7 +332,7 @@ Deployed workflows-starter triggers (1.12 sec)
336332
workflow: workflows-starter
337333
```
338334

339-
A Worker with a valid Workflow definition will be automatically registered by Workflows. You can list your current Workflows using wrangler:
335+
A Worker with a valid Workflow definition will be automatically registered by Workflows. You can list your current Workflows using Wrangler:
340336

341337
```sh
342338
npx wrangler workflows list
@@ -355,16 +351,16 @@ Showing last 1 workflow:
355351
With your Workflow deployed, you can now run it.
356352

357353
1. A Workflow can run in parallel: each unique invocation of a Workflow is an _instance_ of that Workflow.
358-
2. An instance will run to completion (success or failure)
354+
2. An instance will run to completion (success or failure).
359355
3. Deploying newer versions of a Workflow will cause all instances after that point to run the newest Workflow code.
360356

361357
:::note
362358

363-
Because Workflows can be long running, it's possible to have running instances that represent different versions of your Workflow code over time.
359+
Because Workflows can be long running, it is possible to have running instances that represent different versions of your Workflow code over time.
364360

365361
:::
366362

367-
To trigger our Workflow, we will use the `wrangler` CLI and pass in an optional `--payload`. The `payload` will be passed to your Workflow's `run` method handler as an `Event`
363+
To trigger our Workflow, we will use the `wrangler` CLI and pass in an optional `--payload`. The `payload` will be passed to your Workflow's `run` method handler as an `Event`.
368364

369365
```sh
370366
npx wrangler workflows trigger workflows-starter '{"hello":"world"}'
@@ -447,7 +443,7 @@ From the output above, we can inspect:
447443
* The status (success, failure, running) of each step
448444
* Any state emitted by the step
449445
* Any `sleep` state, including when the Workflow will wake up
450-
* Retries associated with each step.
446+
* Retries associated with each step
451447
* Errors, including exception messages
452448

453449
:::note
@@ -480,8 +476,8 @@ Re-deploying the Workers script containing your Workflow code will re-create the
480476

481477
## Next steps
482478

483-
* Learn more about [how events are passed to a Workflow](/workflows/build/events-and-parameters/)
484-
* Binding to and triggering Workflow instances using the [Workers API](/workflows/build/workers-api/)
485-
* The [Rules of Workflows](/workflows/build/rules-of-workflows/) and best practices for building applications using Workflows.
479+
* Learn more about [how events are passed to a Workflow](/workflows/build/events-and-parameters/).
480+
* Learn more about binding to and triggering Workflow instances using the [Workers API](/workflows/build/workers-api/).
481+
* Learn more about the [Rules of Workflows](/workflows/build/rules-of-workflows/) and best practices for building applications using Workflows.
486482

487483
If you have any feature requests or notice any bugs, share your feedback directly with the Cloudflare team by joining the [Cloudflare Developers community on Discord](https://discord.cloudflare.com).

0 commit comments

Comments
 (0)