Use the QStash Function Scheduler
Deploy the QStash Function Scheduler template, which dispatches a schedule you configure through QStash.
The QStash Function Scheduler template is designed to set up and manage a custom function, which receives a user-configured schedule and dispatches it through QStash, a message queue and task scheduler for serverless runtimes.
Prerequisites
Before using this template, you need to:
- Create an Upstash account.
- In the Upstash Console, get your Current Signing Key, Next Signing Key, and QStash Token within the QStash tab.
- Have a GitHub account to connect with Azion and create your new repository.
- Every push will be deployed automatically to this repository to keep your project updated.
- This template uses Functions, and it may generate usage-related costs. Check the pricing page for more information.
Deploy the template
You obtain and configure the template through Azion Console. To deploy it, select the button below.
DeploySet up the template
The configuration form carries the information that configures your application. To fill it in:
A window opens to confirm the installation of the Azion GitHub App, a tool that connects your GitHub account with Azion’s platform. Define your permissions and repository access as desired.
The bucket for storage and the function use the same name. Use a unique, memorable name. If the name is already taken, the platform returns an error message.
Both keys are required, and both come from the QStash tab of your Upstash Console.
- QStash Current Signing Key: a string to sign all messages sent to the destination. Copy it from
QSTASH_CURRENT_SIGNING_KEY. - QStash Next Signing Key: a string used to sign messages after you have rotated your signing keys. Copy it from
QSTASH_NEXT_SIGNING_KEY.
During the deployment, a window shows the logs. When it completes, the page shows the application and the options to continue.
Key configurations
When deployed, this template creates a function built with the arguments you provided. It also creates a GitHub repository that carries an automation for continuous deployment, and it creates and instantiates an application and its domain.
Schedule tasks
After the deployment finishes and propagates, you can start scheduling tasks.
To do so, you have two options: via terminal or via Upstash console.
Via terminal
To schedule a task from your development environment:
In the Upstash Console, copy the QSTASH_TOKEN from the QStash tab.
Use the following examples for your request, according to the interval required.
Once
Every minute
Every 10 minutes
Every hour
Where:
| Flag | Description |
|---|---|
--request POST | Specifies the method of request sent. In this case, a HTTP POST method to post or schedule a HTTP message. |
-H "Authorization" | Provides authorization information through a token for authentication. You must add your QStash token here. |
-H "Content-Type" | Specifies the content type of the request body. In this case, JSON format. |
-H "Upstash-Cron" | Schedules a cron-like job in Upstash, allowing you to automate tasks at specific intervals. |
-d | Provides the data for the request body, including the JSON payload. The backslashes (\) before the double quotes (") are used to ensure that the quotes are treated as part of the data within the JSON payload. |
Your task is scheduled and will be executed according to the defined scheduling.
Your scheduled tasks are visible in the Upstash Console, within the QStash tab, for your review and monitoring.
Via Upstash console
To schedule a task from the Upstash Console:
Go to the Upstash Console and open the QStash tab.
In the type field, select Scheduled and choose the delay. To send an immediate and unique message instead, select Once.
Your task is scheduled and visible in the Scheduled Jobs section for your review and monitoring.
Manage the template
Considering that this initial setup may not be optimal for your specific application, all settings can be customized at any time in Azion Console. Once the template is deployed, you also have full control over customizing your Upstash account and QStash configurations.
To manage and edit your application’s settings:
Access Azion Console > Products menu > Applications. The Applications page lists every application on the account.
The list is organized alphabetically. The search bar filters by Application Name.
The page that opens carries every setting you can configure.
Add a custom domain
The application created during the deployment has an assigned Azion Workload domain to make it accessible through the browser. The domain has the following format: xxxxxxxxxx.map.azionedge.net/. However, you can add a custom domain for users to access your application through it.
For more information, refer to Add a custom domain to a workload.