de302858f8
* Started building out the docs navigation * Drafted out a lot of the docs pages. With just titles and descriptions with a coming soon message for now. * A ton more scaffolded pages with titles, descriptions, coming soon/incomplete docs messages * Created the remaining page stubs * Introduction page improvements * Lots of docs changes, mostly the task overview page * Moved some bits around * Task overview fleshed out * Triggering docs page * Regular task page * CLi dev docs * Docs for debugging locally * Environment variables docs * Added env var images * Deployment guides * Updated the title of “Integrations” to “Deployment integrations” to make it less confusing * Lots more docs pages * Changed the language to JavaScript * Fixed typos about queues and added a simple code sample * Moved the local debugger docs into the CLI dev page * Added the CLI deploy options * Delete the local debugger page * Updated the logging page with structured logging * Added the new CLI deploy options * Change to h4 for one of the options * Errors page * WIP on retrying * Retrying guide * Wait docs pages * Queuing docs simplified, partial written * Queuing and concurrency docs * Run tests docs * New combined error and retrying page * Errors and retrying page updated * More docs * Added a possible configurations coming soon table * Created a limits page * Added warnings about how you need to get early access * Minor fixes for the docs
39 lines
1.1 KiB
Plaintext
39 lines
1.1 KiB
Plaintext
---
|
|
title: "Wait until"
|
|
description: "Wait until a date, then continue execution."
|
|
---
|
|
|
|
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.
|
|
|
|
<Snippet file="v3/paused-execution-free.mdx" />
|
|
|
|
## `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.
|