Skip to content

Commit 08afc80

Browse files
committed
sleeping / retrying
1 parent 1fdb278 commit 08afc80

File tree

3 files changed

+77
-9
lines changed

3 files changed

+77
-9
lines changed

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

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,40 @@ A Workflow instance that is resuming from sleep will take priority over newly sc
1818

1919
:::
2020

21-
### Explicitly pausing a Workflow
22-
23-
TODO
24-
25-
### Resuming a Workflow
26-
27-
TODO
2821

2922
## Retrying steps
3023

31-
TODO
24+
Each call to `step.do` in a Workflow accepts an optional `StepConfig`, which allows you define the retry behaviour for that step.
25+
26+
If you do not provide your own retry configuration, Workflows applies the following defaults:
27+
28+
```ts
29+
const defaultConfig: WorkflowStepConfig = {
30+
retries: {
31+
limit: 5,
32+
delay: 1000,
33+
backoff: "constant",
34+
},
35+
timeout: "15 minutes",
36+
};
37+
```
38+
39+
When providing your own `StepConfig`, you can configure:
40+
41+
* The total number of attempts to make for a step
42+
* The delay between attempts
43+
* What backoff algorithm to apply between each attempt: any of `constant`, `linear`, or `exponential`
44+
* When to timeout (in duration) before considering the step as failed (including during a retry attempt).
45+
46+
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`:
47+
48+
```ts
49+
let someState = step.do("call an API", {
50+
retries: {
51+
limit: 10, // The total number of attempts
52+
delay: "10 seconds", // Delay between each retry
53+
backoff: "exponential" // Any of "constant" | "linear" | "exponential";
54+
},
55+
timeout: "30 minutes",
56+
}, async () => { /* Step code goes here /* }
57+
```

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,48 @@ export default {
8181
};
8282
```
8383

84+
### Explicitly pausing a Workflow
85+
86+
You can explicitly pause a Workflow instance (and later resume it) by calling `pause` against a specific instance ID.
87+
88+
```ts
89+
let instance = await env.MY_WORKFLOW.get("abc-123")
90+
await instance.pause() // Returns Promise<void>
91+
```
92+
93+
### Resuming a Workflow
94+
95+
You can resume a paused Workflow instance by calling `resume` against a specific instance ID.
96+
97+
```ts
98+
let instance = await env.MY_WORKFLOW.get("abc-123")
99+
await instance.resume() // Returns Promise<void>
100+
```
101+
102+
Calling `resume` on an instance that is not currently paused will have no effect.
103+
104+
### Stopping a Workflow
105+
106+
You can stop a Workflow instance by calling `abort` against a specific instance ID.
107+
108+
```ts
109+
let instance = await env.MY_WORKFLOW.get("abc-123")
110+
await instance.abort() // Returns Promise<void>
111+
```
112+
113+
Once stopped, the Workflow instance *cannot* be resumed.
114+
115+
### Restarting a Workflow
116+
117+
You can restart a Workflow instance by calling `restart` against a specific instance ID.
118+
119+
```ts
120+
let instance = await env.MY_WORKFLOW.get("abc-123")
121+
await instance.restart() // Returns Promise<void>
122+
```
123+
124+
Restarting an instance will immediately cancel any in-progress steps, erase any intermediate state, and treat the Workflow as if it was run for the first time.
125+
84126
## REST API (HTTP)
85127

86128
TODO

src/content/docs/workflows/get-started/cli-quick-start.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Specifically, the code above:
148148
4. Defines a custom retry configuration for a step.
149149
5. Binds to the Workflow from a Worker's `fetch` handler so that we can create (trigger) instances of our Workflow via a HTTP call.
150150

151-
You can edit the Workflow by adding (or removing) additional `step` calls, changing the retry configuration, and/or making your own API calls. This Workflow template is designed to illustrate some of Workflows APIs.
151+
You can edit this Workflow by adding (or removing) additional `step` calls, changing the retry configuration, and/or making your own API calls. This Workflow template is designed to illustrate some of Workflows APIs.
152152

153153
## 2. Deploy a Workflow
154154

0 commit comments

Comments
 (0)