Skip to content

Commit 883e24a

Browse files
committed
sleep
1 parent f9eccb3 commit 883e24a

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,47 @@ sidebar:
66

77
---
88

9-
TODO
9+
This guide details how to sleep a Workflow and/or configure retries for a Workflow step.
1010

1111
## Sleeping
1212

13-
TODO
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.
1414

1515
:::note
1616

1717
A Workflow instance that is resuming from sleep will take priority over newly scheduled (queued) instances. This helps ensure that older Workflow instances can run to completion and are not blocked by newer instances.
1818

1919
:::
2020

21+
### Sleep for a relative period
22+
23+
Use `step.sleep` to have a Workflow sleep for a relative period of time:
24+
25+
```ts
26+
await step.sleep("sleep for a bit", "1 hour")
27+
```
28+
29+
The second argument to `step.sleep` accepts both `number` (seconds) or a human-readable format, such as "1 minute" or "26 hours". The accepted units for `step.sleep` when used this way are as follows:
30+
31+
```ts
32+
| "second"
33+
| "minute"
34+
| "hour"
35+
| "day"
36+
| "week"
37+
| "month"
38+
| "year"
39+
```
40+
41+
### Sleep until a fixed date
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)
44+
45+
```ts
46+
// sleepUntil accepts a Date object as its second argument
47+
const workflowsLaunchDate = Date.parse("24 Oct 2024 13:00:00 UTC");
48+
await step.sleepUntil("sleep until X times out", workflowsLaunchDate)
49+
```
2150

2251
## Retrying steps
2352

0 commit comments

Comments
 (0)