0d4e3e70c1
* tasks no longer inside a group in the side menu (and added “cron”) * Delay using a timezone * Added React Not Defined error to the troubleshooting page * Improved the React common problem * Link to v2 docs * New Development section and entry in Common Problems * Concurrently running the terminal * Fixed the .env weirdness * Added section on creating PATs for Github actions * Improved the Machine spec and limits page * Quick start steps now have nice images * Added a diagram for the lifecycle functions * Added note about onFailure * CRON -> cron/Cron * Updated the cli-dev steps for the concurrently package * Fixed capital letter * Updated diagram text * Removed dead page
41 lines
1.1 KiB
Plaintext
41 lines
1.1 KiB
Plaintext
---
|
|
title: "Wait until"
|
|
description: "Wait until a date, then continue execution."
|
|
---
|
|
|
|
import PausedExecutionFree from "/snippets/paused-execution-free.mdx"
|
|
|
|
This example sends a reminder email to a user at the specified datetime.
|
|
|
|
```ts /trigger/reminder-email.ts
|
|
export const sendReminderEmail = task({
|
|
id: "send-reminder-email",
|
|
run: async (payload: { to: string; name: string; date: string }) => {
|
|
//wait until the date
|
|
await wait.until({ date: new Date(payload.date) });
|
|
|
|
//todo send email
|
|
const { data, error } = await resend.emails.send({
|
|
from: "hello@trigger.dev",
|
|
to: payload.to,
|
|
subject: "Don't forget…",
|
|
html: `<p>Hello ${payload.name},</p><p>...</p>`,
|
|
});
|
|
},
|
|
});
|
|
```
|
|
|
|
This allows you to write linear code without having to worry about the complexity of scheduling or managing cron jobs.
|
|
|
|
<PausedExecutionFree />
|
|
|
|
## `throwIfInThePast`
|
|
|
|
You can optionally throw an error if the date is already in the past when the function is called:
|
|
|
|
```ts
|
|
await wait.until({ date: new Date(date), throwIfInThePast: true });
|
|
```
|
|
|
|
You can of course use try/catch if you want to do something special in this case.
|