How to use the QStash EdgeFunction Scheduler template through Azion
Preview
The QStash EdgeFunction Scheduler template is designed to set up and manage a custom edge function, which receives a user-configured schedule and dispatches it through QStash, a message queue and task scheduler for serverless runtimes.
Requirements
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.
- Enable Edge Functions in your Azion account.
- To do so:
- Access Console > Account menu.
- Select the Billing & Subscriptions option.
- Select the Subscriptions tab.
- Activate the switch for the module.
Deploying the template
You can obtain and configure your template through the Azion Console. To easily deploy it at the edge, click the button below.
DeploySetting up the template
In the configuration form, you must provide the information to configure your Azion application. Fill in the presented fields.
- Connect Azion with your GitHub account.
- A pop-up window will open 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.
- Select the Git Scope to work with.
- Define a name for your edge application.
- The bucket for storage and the edge function will use the same name.
- Use a unique and easy-to-remember name. If the name has already been used, the platform returns an error message.
- Enter the following information:
- QStash Current Signing Key *: a string to sign all messages sent to the destination.
- Go to your Upstash Console and copy the
QSTASH_CURRENT_SIGNING_KEY
from the Qstash tab.
- Go to your Upstash Console and copy the
- QStash Next Signing Key *: a string used to sign messages after you’ve rotated your signing keys.
- Go to your Upstash Console and copy the
QSTASH_NEXT_SIGNING_KEY
from the Qstash tab.
- Go to your Upstash Console and copy the
- Click the Deploy button to start the deployment process.
During the deployment, you’ll be able to follow the process through a window showing off the logs. When it’s complete, the page shows information about the application and some options to continue your journey.
Key configurations
When deployed, this template creates an edge function built with the arguments provided by the user. It also creates a new GitHub repository that includes an automation to enable continuous deployment. Additionally, the template creates and instantiates an edge application and its domain to ease the interaction with the edge function.
Scheduling tasks
After the deployment is finished and propagated, you’re able to start scheduling tasks.
To do so, you have two options: via terminal or via Upstash console.
Via terminal
- Get your application domain.
- In the Upstash Console, copy the
QSTASH_TOKEN
from the QStash tab. - In your development environment, open the terminal.
- Make an HTTP POST request to the specified URL to schedule your messages.
Use the following exemples 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. |
Done. 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
- Copy your Azion application domain.
- Go to the Upstash Console and open the QStash tab.
- Complete the form with the requested information.
- In the type field, select Scheduled and choose the delay.
- Alternatively, select Once to send an immediate and unique message.
- Click the Schedule button.
Done. Your task is scheduled and visible in the Scheduled Jobs section for your review and monitoring.
Managing the template
Considering that this initial setup may not be optimal for your specific edge 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 edge application’s settings, follow these steps:
- Access Console.
- On the upper-left corner, select Products menu > Edge Application.
- You’ll be redirected to the Edge Application page. It lists all the edge applications you’ve created.
- Find the edge application relate to the Qstash Scheduler template and select it.
- The list is organized alphabetically. You can also use the search bar located in the upper-left corner of the list; currently, it filters only by Application Name.
After selecting the edge application you’ll work on, you’ll be directed to a page containing all the settings you can configure.
Adding a custom domain
The edge application created during the deployment has an assigned Azion 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 edge application through it.
Learn how to use the QStash EdgeFunction Scheduler template through Azion. Watch the video below: