Skip to content

Commit f480fd5

Browse files
committed
Wait docs pages
1 parent 1927d15 commit f480fd5

File tree

7 files changed

+68
-10
lines changed

7 files changed

+68
-10
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<Note>
2+
In the Trigger.dev Cloud we automatically pause execution of tasks when they are waiting for
3+
longer than a few seconds. You are not charged when execution is paused.
4+
</Note>

docs/v3/tasks-regular.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const emailSequence = task({
3636
//send the first email immediately
3737
const firstEmailResult = await retry.onThrow(
3838
async ({ attempt }) => {
39-
const { data, error } = resend.emails.send({
39+
const { data, error } = await resend.emails.send({
4040
4141
to: payload.email,
4242
subject: "Welcome to Trigger.dev",
@@ -59,7 +59,7 @@ export const emailSequence = task({
5959
//send the second email
6060
const secondEmailResult = await retry.onThrow(
6161
async ({ attempt }) => {
62-
const { data, error } = resend.emails.send({
62+
const { data, error } = await resend.emails.send({
6363
6464
to: payload.email,
6565
subject: "Some tips for you",

docs/v3/wait-for-event.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ title: "Wait for event"
33
description: "Wait until an event has been received, then continue execution."
44
---
55

6-
<Snippet file="incomplete-docs.mdx" />
6+
<Snippet file="coming-soon.mdx" />

docs/v3/wait-for-request.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ title: "Wait for request"
33
description: "Wait until a `Request` has been received at the provided URL, then continue execution."
44
---
55

6-
<Snippet file="incomplete-docs.mdx" />
6+
<Snippet file="coming-soon.mdx" />

docs/v3/wait-for.mdx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,29 @@ title: "Wait for"
33
description: "Wait for a period of time, then continue execution."
44
---
55

6-
<Snippet file="incomplete-docs.mdx" />
6+
Inside your tasks you can wait for a period of time before you want execution to continue.
7+
8+
```ts /trigger/long-task.ts
9+
export const veryLongTask = task({
10+
id: "very-long-task",
11+
run: async (payload) => {
12+
await wait.for({ seconds: 5 });
13+
14+
await wait.for({ minutes: 10 });
15+
16+
await wait.for({ hours: 1 });
17+
18+
await wait.for({ days: 1 });
19+
20+
await wait.for({ weeks: 1 });
21+
22+
await wait.for({ months: 1 });
23+
24+
await wait.for({ years: 1 });
25+
},
26+
});
27+
```
28+
29+
This allows you to write linear code without having to worry about the complexity of scheduling or managing CRON jobs.
30+
31+
<Snippet file="v3/paused-execution-free.mdx" />

docs/v3/wait-until.mdx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,36 @@ title: "Wait until"
33
description: "Wait until a date, then continue execution."
44
---
55

6-
<Snippet file="incomplete-docs.mdx" />
6+
This example sends a reminder email to a user at the specified datetime.
7+
8+
```ts /trigger/reminder-email.ts
9+
export const sendReminderEmail = task({
10+
id: "send-reminder-email",
11+
run: async (payload: { to: string; name: string; date: string }) => {
12+
//wait until the date
13+
await wait.until({ date: new Date(payload.date) });
14+
15+
//todo send email
16+
const { data, error } = await resend.emails.send({
17+
18+
to: payload.to,
19+
subject: "Don't forget…",
20+
html: `<p>Hello ${payload.name},</p><p>...</p>`,
21+
});
22+
},
23+
});
24+
```
25+
26+
This allows you to write linear code without having to worry about the complexity of scheduling or managing CRON jobs.
27+
28+
<Snippet file="v3/paused-execution-free.mdx" />
29+
30+
## `throwIfInThePast`
31+
32+
You can optionally throw an error if the date is already in the past when the function is called:
33+
34+
```ts
35+
await wait.until({ date: new Date(date), throwIfInThePast: true });
36+
```
37+
38+
You can of course use try/catch if you want to do something special in this case.

docs/v3/wait.mdx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ description: "During your run you can wait for a period of time or for something
66

77
Waiting allows you to write complex tasks as a set of async code, without having to scheduled another task or poll for changes.
88

9-
<Note>
10-
In the cloud product we automatically pause execution of tasks if the wait is longer than a few
11-
seconds. You are not charged for the time spent waiting.
12-
</Note>
9+
<Snippet file="v3/paused-execution-free.mdx" />
1310

1411
| Function | What it does |
1512
| ----------------------------------------- | ----------------------------------------------------------------------------------------- |

0 commit comments

Comments
 (0)