This example demonstrates a customer onboarding process using Upstash Workflow. The following example workflow registers a new user, sends welcome emails, and periodically checks and responds to the user's activity state.
Use Case#
Our workflow will:
- Register a new user to our service
- Send them a welcome email
- Wait for a certain time
- Periodically check the user's state
- Send appropriate emails based on the user's activity
Code Example#
Code Breakdown#
1. New User Signup#
We start by sending a newly signed-up user a welcome email:
2. Initial Waiting Period#
To leave time for the user to interact with our platform, we use context.sleep to pause our workflow for 3 days:
3. Periodic State Check#
We enter an infinite loop to periodically (every month) check the user's engagement level with our platform and send appropriate emails:
Key Features#
-
Non-blocking sleep: We use
context.sleepfor pausing the workflow without consuming execution time (great for optimizing serverless cost). -
Long-running task: This workflow runs indefinitely, checking and responding to a users engagement state every month.