task()
function and can be triggered from your backend or inside another task.
Like all tasks they don’t have timeouts, they should be placed inside a /trigger folder, and you can configure them.
Example tasks
A task that does an OpenAI call with retrying
Sometimes OpenAI calls can take a long time to complete, or they can fail. This task will retry if the API call fails completely or if the response is empty./trigger/openai.ts
A Task that sends emails in a sequence with delays in between
This example uses Resend to send a sequence of emails over several days. Each email is wrapped inretry.onThrow
. This will retry the block of code if an error is thrown. This is useful when you don’t want to retry the whole task, but just a part of it. The entire task will use the default retrying, so can also retry.
Additionally this task uses wait.for
to wait for a certain amount of time before sending the next email. During the waiting time, the task will be paused and will not consume any resources.
/trigger/email-sequence.ts