---
name: azion-use-the-qstash-function-scheduler
description: >-
  Deploy the QStash Function Scheduler template, which dispatches a schedule you configure through QStash.
---

# Use the QStash Function Scheduler

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](https://console.upstash.com/).
- In the [Upstash Console](https://console.upstash.com/qstash), get your **Current Signing Key**, **Next Signing Key**, and **QStash Token** within the **QStash** tab.
- Have a [GitHub account](https://github.com/signup) 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](/en/documentation/platform/functions/), and it may generate usage-related costs. Check the [pricing page](https://www.azion.com/en/pricing/) for more information.

> **warning**
>
> Any cost generated by QStash usage will be processed and billed separately on the Upstash platform. Visit the [QStash documentation](https://upstash.com/docs/qstash/overall/getstarted) for more details.

---

## Deploy the template

You obtain and configure the template through Azion Console. To deploy it, select the button below.

[Deploy](https://console.azion.com/create/upstash/qstash-edgefunction-scheduler)

---

## Set up the template

The configuration form carries the information that configures your application. To fill it in:

1. **Connect Azion with your GitHub account**

   A window opens to confirm the installation of the [Azion GitHub App](https://www.azion.com/en/documentation/guides/application-development/automation/azion-github-app/), a tool that connects your GitHub account with Azion's platform. Define your permissions and repository access as desired.

2. **Select the Git Scope to work with**

3. **Define a name for your application**

   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.

4. **Enter the QStash signing keys**

   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`.

5. **Select Deploy to start the deployment**

During the deployment, a window shows the logs. When it completes, the page shows the application and the options to continue.

> **Note**
>
> The link opens the application in the browser. Propagating and configuring the application across Azion's distributed network takes a few minutes, so the URL may not answer immediately.

### 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.

> **Note**
>
> The tasks must be scheduled in any format that can be transmitted in the HTTP request, such as JSON, XML, or binary. The examples below are using JSON.

To do so, you have two options: [via terminal](#via-terminal) or [via Upstash console](#via-upstash-console).

### Via terminal

To schedule a task from your development environment:

1. **Get your application domain**

2. **Copy your QStash token**

   In the [Upstash Console](https://console.upstash.com/qstash), copy the `QSTASH_TOKEN` from the **QStash** tab.

3. **Open the terminal in your development environment**

4. **Make an HTTP POST request to the specified URL to schedule your messages**

   Use the following examples for your request, according to the interval required.

#### Once

```bash
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

```bash
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

```bash
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

```bash
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:

| 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](https://console.upstash.com/qstash), within the **QStash** tab, for your review and monitoring.

### Via Upstash console

To schedule a task from the Upstash Console:

1. **Copy your Azion application domain**

2. **Open the QStash tab**

   Go to the [Upstash Console](https://console.upstash.com/qstash) and open the **QStash** tab.

3. **Complete the form with the requested information**

   In the type field, select *Scheduled* and choose the delay. To send an immediate and unique message instead, select *Once*.

4. **Select Schedule**

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

> **Note**
>
> You can also publish them using a REST API request. For more information, read the [QStash documentation](https://upstash.com/docs/qstash/api-reference/messages/publish-a-message).

---

## 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](https://console.azion.com). 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:

1. **Open the Applications page**

   Access [Azion Console](https://console.azion.com/) > **Products menu** > **Applications**. The **Applications** page lists every application on the account.

2. **Find the application related to the QStash Function Scheduler template**

   The list is organized alphabetically. The **search bar** filters by **Application Name**.

3. **Select the application**

   The page that opens carries every setting you can configure.

> **Tip**
>
> Read the documentation about [managing applications](/en/documentation/platform/applications/quickstart/) for more details. For specific Upstash or QStash-related questions, check the [Upstash documentation](https://docs.upstash.com/).

### 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](/en/documentation/guides/platform/migration/configure-a-domain/).
