You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/workflows/build/dynamic-steps.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,12 +8,12 @@ sidebar:
8
8
9
9
A Workflow does not have to define all of its steps statically: steps can be created programmatically and/or conditionally.
10
10
11
-
This allows you to not only trigger steps based on specific input parameters, but to also name steps dynamically, set the retry configuration for a step
11
+
This allows you to not only trigger steps based on specific input parameters, but to also name steps dynamically and set the retry configuration for a single step.
12
12
13
13
14
14
## Example
15
15
16
-
Steps can be created on-the-fly, allowing you create a step for each parameter passed to your Workflow, for each file you want to read from storage, or for calls to third-party APIs.
16
+
You can create steps on-the-fly. You can create a step for each parameter passed to your Workflow, for each file you want to read from storage, or for calls to third-party APIs.
17
17
18
18
For example, you can loop over each event, label the step dynamically, and have the step operate only over that `event`:
Copy file name to clipboardExpand all lines: src/content/docs/workflows/build/events-and-parameters.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,11 +10,11 @@ When a Workflow is triggered, it can receive an optional event. This event can i
10
10
11
11
Events are a powerful part of a Workflow, as you often want a Workflow to act on data. Because a given Workflow instance executes durably, events are a useful way to provide a Workflow with data that should be immutable (not changing) and/or represents data the Workflow needs to operate on at that point in time.
12
12
13
-
## Passing parameters to a Workflow
13
+
## Pass parameters to a Workflow
14
14
15
15
You can pass parameters to a Workflow in two ways:
16
16
17
-
* As an optional argument to the `create` method on a [Workflow binding] when triggering a Workflow from a Worker.
17
+
* As an optional argument to the `create` method on a [Workflow binding](/workers/wrangler/commands/#trigger) when triggering a Workflow from a Worker.
18
18
* Via the `--params` flag when using the `wrangler` CLI to trigger a Workflow.
19
19
20
20
You can pass any JSON-serializable object as a parameter.
@@ -80,7 +80,7 @@ interface YourEventType {
80
80
}
81
81
```
82
82
83
-
When we pass our`YourEventType` to `WorkflowEvent` as a type parameter, the `event.payload` property now has the type `YourEventType` throughout our workflow definition:
83
+
When you pass your`YourEventType` to `WorkflowEvent` as a type parameter, the `event.payload` property now has the type `YourEventType` throughout your workflow definition:
Copy file name to clipboardExpand all lines: src/content/docs/workflows/build/rules-of-workflows.mdx
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,16 @@ sidebar:
5
5
order: 10
6
6
---
7
7
8
-
A Workflow contains one or more steps. Each step is a self-contained, individually retriable component of a Workflow. Steps may emit (optional) state that allows a Workflow to persist and continue from that step, even if a Workflow fails due to a network or infrastructure issue. A Workflow is comprised of one or more steps.
8
+
A Workflow contains one or more steps. Each step is a self-contained, individually retriable component of a Workflow. Steps may emit (optional) state that allows a Workflow to persist and continue from that step, even if a Workflow fails due to a network or infrastructure issue.
9
9
10
10
This is a small guidebook on how to build more resilient and correct Workflows.
11
11
12
12
### Ensure API/Binding calls are idempotent
13
13
14
14
Because a step might be retried multiple times, your steps should (ideally) be idempotent. For context, idempotency is a logical property where the operation (in this case a step),
15
-
can be applied multiple times without changing the result beyond the intial application.
15
+
can be applied multiple times without changing the result beyond the initial application.
16
16
17
-
As an example, let's assume you have a Workflow that charges your customers and you really don't want to charge them twice by accident, before charging them, you should
17
+
As an example, let us assume you have a Workflow that charges your customers, and you really do not want to charge them twice by accident. Before charging them, you should
18
18
check if they were already charged:
19
19
20
20
```ts
@@ -55,13 +55,13 @@ export class MyWorkflow extends WorkflowEntrypoint {
55
55
56
56
:::note
57
57
58
-
Guaranteeing idempotency might be optional in your specific use-case and implementation, although we recommend it to always try to guarantee it.
58
+
Guaranteeing idempotency might be optional in your specific use-case and implementation, but we recommend that you always try to guarantee it.
59
59
60
60
:::
61
61
62
62
### Make your steps granular
63
63
64
-
Steps should be as self-contained as possible, this allows your own logic to be more durable in case of failures in third-party APIs, network errors, and so on.
64
+
Steps should be as self-contained as possible. This allows your own logic to be more durable in case of failures in third-party APIs, network errors, and so on.
65
65
66
66
You can also think of it as a transaction, or a unit of work.
67
67
@@ -85,12 +85,12 @@ export class MyWorkflow extends WorkflowEntrypoint {
85
85
}
86
86
```
87
87
88
-
Otherwise your entire workflow might not be as durable as you might think, and encounter into some undefined behaviour and you can avoid them by:
88
+
Otherwise, your entire Workflow might not be as durable as you might think, and you may encounter some undefined behaviour. You can avoid them by following the rules below:
89
89
90
90
- 🔴 Do not encapsulate your entire logic in one single step.
91
-
- 🔴 Do not call seperate services in the same step (unless you need it to prove idempotency)
92
-
- 🔴 Do not make too many service calls in the same step (unless you need it to prove idempotency)
93
-
- 🔴 Do not do too much CPU-intensive work inside of a single step - sometimes engine might have to restart and it will start over from that step.
91
+
- 🔴 Do not call separate services in the same step (unless you need it to prove idempotency).
92
+
- 🔴 Do not make too many service calls in the same step (unless you need it to prove idempotency).
93
+
- 🔴 Do not do too much CPU-intensive work inside a single step - sometimes the engine may have to restart, and it will start over from the beginning of that step.
94
94
95
95
```ts
96
96
exportclassMyWorkflowextendsWorkflowEntrypoint {
@@ -106,9 +106,9 @@ export class MyWorkflow extends WorkflowEntrypoint {
106
106
}
107
107
```
108
108
109
-
### Don't rely on state outside of a step
109
+
### Do not rely on state outside of a step
110
110
111
-
Workflows may hibernate and lose all in-memory state. This will happen when engine detects that there's no pending work and can hibernate until it needs to wake-up (because of a sleep, retry or event).
111
+
Workflows may hibernate and lose all in-memory state. This will happen when engine detects that there is no pending work and can hibernate until it needs to wake-up (because of a sleep, retry, or event).
112
112
113
113
This means that you should not store state outside of a step:
114
114
@@ -193,7 +193,7 @@ export class MyWorkflow extends WorkflowEntrypoint {
193
193
}
194
194
```
195
195
196
-
### Don't mutate your incoming events
196
+
### Do not mutate your incoming events
197
197
198
198
The `event` passed to your Workflow's `run` method is immutable: changes you make to the event are not persisted across steps and/or Workflow restarts.
Copy file name to clipboardExpand all lines: src/content/docs/workflows/build/sleeping-and-retrying.mdx
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ sidebar:
8
8
9
9
This guide details how to sleep a Workflow and/or configure retries for a Workflow step.
10
10
11
-
## Sleeping
11
+
## Sleep a Workflow
12
12
13
13
You can set a Workflow to sleep as an explicit step, which can be useful when you want a Workflow to wait, schedule work ahead, or pause until an input or other external state is ready.
14
14
@@ -40,15 +40,15 @@ The second argument to `step.sleep` accepts both `number` (seconds) or a human-r
40
40
41
41
### Sleep until a fixed date
42
42
43
-
Use `step.sleepUntil` to have a Workflow sleep to a specific `Date`: this can be useful when you have a timestamp from another system or want to "schedule" work to occur at a specific time (e.g. Sunday, 9AM UTC)
43
+
Use `step.sleepUntil` to have a Workflow sleep to a specific `Date`: this can be useful when you have a timestamp from another system or want to "schedule" work to occur at a specific time (e.g. Sunday, 9AM UTC).
44
44
45
45
```ts
46
46
// sleepUntil accepts a Date object as its second argument
47
47
const workflowsLaunchDate =Date.parse("24 Oct 2024 13:00:00 UTC");
48
48
awaitstep.sleepUntil("sleep until X times out", workflowsLaunchDate)
49
49
```
50
50
51
-
## Retrying steps
51
+
## Retry steps
52
52
53
53
Each call to `step.do` in a Workflow accepts an optional `StepConfig`, which allows you define the retry behaviour for that step.
54
54
@@ -70,7 +70,7 @@ When providing your own `StepConfig`, you can configure:
70
70
* The total number of attempts to make for a step
71
71
* The delay between attempts
72
72
* What backoff algorithm to apply between each attempt: any of `constant`, `linear`, or `exponential`
73
-
* When to timeout (in duration) before considering the step as failed (including during a retry attempt).
73
+
* When to timeout (in duration) before considering the step as failed (including during a retry attempt)
74
74
75
75
For example, to limit a step to 10 retries and have it apply an exponential delay (starting at 10 seconds) between each attempt, you would pass the following configuration as an optional object to `step.do`:
Copy file name to clipboardExpand all lines: src/content/docs/workflows/build/trigger-workflows.mdx
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ sidebar:
8
8
9
9
You can trigger Workflows both programmatically and via the Workflows APIs, including:
10
10
11
-
1. With [Workers](/workers) via HTTP requests in a `fetch` handler or bindings from a `queue` or `scheduled` handler.
11
+
1. With [Workers](/workers) via HTTP requests in a `fetch` handler, or bindings from a `queue` or `scheduled` handler
12
12
2. Using the [Workflows REST API](/api/paths/accounts-account_id--workflows/get)
13
13
2. Via the [wrangler CLI](/workers/wrangler/commands/#workflows) in your terminal
14
14
@@ -21,7 +21,7 @@ You can interact with a Workflow:
21
21
* Directly over HTTP via the [`fetch`](/workers/runtime-apis/handlers/fetch/) handler
22
22
* From a [Queue consumer](/queues/configuration/javascript-apis/#consumer) inside a `queue` handler
23
23
* From a [Cron Trigger](/workers/configuration/cron-triggers/) inside a `scheduled` handler
24
-
* Within a [Durable Object](/durable-objects/).
24
+
* Within a [Durable Object](/durable-objects/)
25
25
26
26
:::note
27
27
@@ -56,7 +56,7 @@ The following example shows how you can manage Workflows from within a Worker, i
56
56
57
57
* Retrieving the status of an existing Workflow instance by its ID
58
58
* Creating (triggering) a new Workflow instance
59
-
* Returning the status of a given instance ID.
59
+
* Returning the status of a given instance ID
60
60
61
61
```ts title="src/index.ts"
62
62
interfaceEnv {
@@ -93,7 +93,7 @@ export default {
93
93
94
94
### Inspect a Workflow's status
95
95
96
-
You can inspect the status of any running Workflow instance by calling `status` against a specific instance ID. This allows you to programmatically inspect whether an instance is queued (waiting to be scheduled), actively running, paused or errored.
96
+
You can inspect the status of any running Workflow instance by calling `status` against a specific instance ID. This allows you to programmatically inspect whether an instance is queued (waiting to be scheduled), actively running, paused, or errored.
97
97
98
98
```ts
99
99
let instance =awaitenv.MY_WORKFLOW.get("abc-123")
@@ -118,7 +118,7 @@ The possible values of status are as follows:
118
118
};
119
119
```
120
120
121
-
### Explicitly pausing a Workflow
121
+
### Explicitly pause a Workflow
122
122
123
123
You can explicitly pause a Workflow instance (and later resume it) by calling `pause` against a specific instance ID.
124
124
@@ -127,7 +127,7 @@ let instance = await env.MY_WORKFLOW.get("abc-123")
127
127
awaitinstance.pause() // Returns Promise<void>
128
128
```
129
129
130
-
### Resuming a Workflow
130
+
### Resume a Workflow
131
131
132
132
You can resume a paused Workflow instance by calling `resume` against a specific instance ID.
0 commit comments