This example showcases how to send emails with a Restack workflow using the sendgrid api. You can easily choose another email provider and update the code. You can schedule two scenarios of the workflow.
- It will be successfull and send an email.
- The email content generation step will fail once to showcase how Restack handles retries automatically. Once failure is caught, step will be retry automatically and rest of workflow will be executed as expected and email will be sent.
- Node 20 or higher
brew install nvm
nvm use 20
To install the Restack Web UI, you can use Docker.
docker run -d --pull always --name restack -p 5233:5233 -p 6233:6233 -p 7233:7233 ghcr.io/restackio/restack:main
Where all your code is defined, including workflow steps.
add OPENAI_API_KEY, SENDGRID_API_KEY, FROM_EMAIL, TO_EMAIL in .env
npm i
npm run build
npm run dev
Your code will be running and syncing with Restack engine to execute workflows or functions.
In another shell:
npm run schedule
Will schedule to start example workflow immediately. The code for this is on scheduleWorkflow.ts
. In here you can see how the sendEmailWorkflow is scheduled to be executed.
In another shell:
npm run schedule-retries
This will schedule the example workflow to start immediately. The code for this is in scheduleWorkflowRetries.ts
. In this file, you can see how the sendEmailWorkflow
is scheduled for execution. The step to generate email content is intentionally set to fail once, demonstrating how Restack automatically handles retries. After the first failure, the step will succeed on the next retry, and the remaining steps in the workflow will execute as expected.