Schedule repeated runs
You can schedule a workflow to run periodically using a cron definition.
Scheduling a workflow
For example, let’s define a workflow that creates a backup of some important data daily. Our workflow endpoint might look like this:
To run this endpoint on a schedule, navigate to Schedules
in your QStash dashboard and click Create Schedule
:
Enter your live endpoint URL, add a CRON expression to define the interval at which your endpoint is called (i.e. every day, every 15 minutes, …) and click Schedule
:
Your workflow will now run repeatedly at the interval you have defined. For more details on CRON expressions, see our QStash scheduling documentation.
Scheduling a per-user workflow
In order to massively improve the user experience, many applications send weekly summary reports to their users. These could be weekly analytics summaries or SEO statistics to keep users engaged with the platform.
Let’s create a user-specific schedule, sending a first report to each user exactly 7 days after they signed up:
This code will call our workflow every week, starting exactly seven days after a user signs up. Each call to our workflow will contain the respective user’s ID.
Note: when creating a user-specific schedule, pass a unique scheduleId
to ensure the operation is idempotent. (See caveats for more details on why this is important).
Lastly, add the summary-creating and email-sending logic inside of your workflow. For example:
Just like that, each user will receive an account summary every week, starting one week after signing up.
Was this page helpful?