Skip to content

Commit

Permalink
cannot sleep 1 month - it's 30d (#902)
Browse files Browse the repository at this point in the history
* cannot sleep `1 month` - it's 30d

vercel/ms#57

* Update 2022-01-24-workflows-part-I.md

* Update workflows.md

Co-authored-by: swyx <shawnthe1@gmail.com>
  • Loading branch information
gianpaj and swyxio committed Feb 15, 2022
1 parent 6e14025 commit 521d9df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions blog/2022-01-24-workflows-part-I.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function SendReminderEmail(event, context) : Message {

return {
message: { user: event.user, iter: event.iter + 1},
after: "1month"
after: "30 days"
}
}

Expand Down Expand Up @@ -132,7 +132,7 @@ async function SendReminderEmail(user: string) {
// Thanks to Temporal's retry policy, we already
// tried twice, better luck next month 🍀
}
await sleep("1 month");
await sleep("30 days");
}
}
```
Expand Down
4 changes: 4 additions & 0 deletions docs/typescript/workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ await sleep(30 * 24 * 60 * 60 * 1000); // numerical API
await sleep('30 days').catch(() => {
// clean up code if workflow is canceled during sleep
});

// NOT VALID
await sleep('1 month'); // ms package doesnt support "months" https://github.com/vercel/ms/issues/57
// use date-fns and sleepUntil instead, see below
```

With this primitive, you can build other abstractions. For example, a `sleepUntil` function that converts absolute time to relative time with `date-fns`:
Expand Down

0 comments on commit 521d9df

Please sign in to comment.