How to use the QStash EdgeFunction Scheduler template through Azion

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:
  1. Access Console > Account menu.
  2. Select the Billing & Subscriptions option.
  3. Select the Subscriptions tab.
  4. Activate the switch for the module.

Getting the template

To start using the QStash EdgeFunction Scheduler template:

  1. Access Console.
  2. Click the + Create button on the homepage.
  3. In the modal, select the Templates option.
  4. Browse and select the QStash EdgeFunction Scheduler card.

Setting up the template

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

  1. 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.
  1. Select the Git Scope to work with.
  2. 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.
  1. 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.
  • 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.
  1. 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

  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:

Once

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\"}"

Every minute

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\"}"

Every 10 minutes

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\"}"

Every hour

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.

Via Upstash console

  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.


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:

  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.

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.

Go to configuring a domain guide

Contributors