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.


Before using this template, you need to:

  1. Create an Upstash account.
  2. In the Upstash Console, get your Current Signing Key, Next Signing Key, and QStash Token within the QStash tab.
  3. Generate your GitHub personal token.

You must also activate:

Edge Functions

You need to activate this module via Azion Console. To do so:

  1. Access Console > Account menu
  2. Select the Billing & Subscriptions option.
  3. Select the Subscriptions tab.
  4. Activate the switch for the module.

To get the QStash EdgeFunction Scheduler template, access Azion Console and select the Start with a template option on the homepage.

This will open a new page where you can select the QStash EdgeFunction Scheduler card.


In the configuration form, you must provide the information to configure your Azion application. Fill in the presented fields.

Fields identified with an asterisk are mandatory.

  • Application Name *: the name of your edge application. It’s used to identify and manage your application within Azion’s platform.
    • Use a unique and easy-to-remember name. If the name has already been used, the platform returns an error message.
  • 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.
  • 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.
  • GitHub Personal Token *: your GitHub personal token.

After completing all the information, click the Next button, located in the bottom-right corner. This will 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 deployment page appears, confirming the edge application has been successfully created.

This page shows you the following sections:

  • Access your Edge Application section includes the link to visit and explore your edge application.
  • Build Summary contains the application’s name and function.
  • The Deployment details tab can be opened to access the logs related to the deployment.
  • What do you want to do next? provides recommendations regarding advanced options to enhance your edge application: Customize Domain, Manage Edge Application, View Edge Application Metrics, View Edge Application Logs, and the Back to Home button.

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.


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.

  1. Get your application domain.
  2. In the Upstash Console, copy the QSTASH_TOKEN from the QStash tab.
  3. In your development environment, open the terminal.
  4. 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:

Terminal window
curl --request POST "https://qstash.upstash.io/v1/publish/{add your domain here}" \
-H "Authorization: Bearer {add your QStash token here}" \
-H "Content-Type: application/json" \
-d "{ \"hello\": \"world\"}"
Terminal window
curl --request POST "https://qstash.upstash.io/v1/publish/{add your domain here}" \
-H "Authorization: Bearer {add your QStash token here}" \
-H "Content-Type: application/json" \
-H "Upstash-Cron: * * * * *" \
-d "{ \"hello\": \"world\"}"
Terminal window
curl --request POST "https://qstash.upstash.io/v1/publish/{add your domain here}" \
-H "Authorization: Bearer {add your QStash token here}" \
-H "Content-Type: application/json" \
-H "Upstash-Cron: */10 * * * *" \
-d "{ \"hello\": \"world\"}"
Terminal window
curl --request POST "https://qstash.upstash.io/v1/publish/{add your domain here}" \
-H "Authorization: Bearer {add your QStash token here}" \
-H "Content-Type: application/json" \
-H "Upstash-Cron: 0 * * * *" \
-d "{ \"hello\": \"world\"}"

Where:

FlagDescription
--request POSTSpecifies 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.
-dProvides 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.

  1. Copy your Azion application domain.
  2. Go to the Upstash Console and open the QStash tab.
  3. 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.
  1. Click the Schedule button.

Done. Your task is scheduled and visible in the Scheduled Jobs section for your review and monitoring.


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:

  1. Access Console.
  2. 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.
  1. 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.

Once the template is deployed, you can edit and update your args and code, as well as implement a continuous deployment workflow. However, you’ll first need to declare secrets on your project’s GitHub repository to complete the second build with the changes. When the second build is completed, you’ll be able to manage your project with a continuous deployment workflow and edit the args as desired.

To do so, open your QStash EdgeFunction Scheduler repository on GitHub. Then, go to Settings > Secrets and variables > Action to add your variables, following these instructions:

  1. Add the Azion personal token to the secrets:
Terminal window
AZION_PERSONAL_TOKEN=<value>
  1. Add the environments for use in the action workflow in the main.yml file, included in the .github/workflows folder of your repository:
.github/workflows/main.yml
- name: edge-...
id: azion_edge
...
with:
....
azionPersonalToken: ${{ secrets.AZION_PERSONAL_TOKEN }}
....
  1. Add the Upstash Signing Keys to the secrets, being:
  • 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 in the QStash tab.
  • 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.
Terminal window
QSTASH_CURRENT_SIGNING_KEY=<value>
QSTASH_NEXT_SIGNING_KEY=<value>
  1. Add the environments for use in the action workflow in the main.yml file, included in the .github/workflows folder of your repository:
.github/workflows/main.yml
- name: Create args file
run: |
...
"QSTASH_CURRENT_SIGNING_KEY": "${{ secrets.QSTASH_CURRENT_SIGNING_KEY }}",
"QSTASH_NEXT_SIGNING_KEY": "${{ secrets.QSTASH_NEXT_SIGNING_KEY }}"
...
  1. Open a pull request to merge the changes to the main branch and start the automatic deployment.

Now, your project is ready to work with a continuous deployment workflow, updating instantly any changes in the application or the repository.

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.

go to Domains reference

Contributors