You can find the project source code on GitHub.
Deploy the project to Cloudflare Workers with a single click.
This guide provides detailed, step-by-step instructions on how to use and deploy Upstash Workflow with Cloudflare Workers. You can also explore our Cloudflare Workers example or Hono.js Cloudflare Workers example for detailed, end-to-end examples and best practices.
If you haven’t obtained your QStash API key yet, you can do so by signing up for an Upstash account and navigating to your QStash dashboard.
First, install the Workflow SDK in your worker project:
Create a .dev.vars
file in your project root and add your QStash token. This key is used to authenticate your application with the QStash service.
Upstash Workflow is powered by QStash, which requires access to your endpoint to execute workflows. When your app is deployed, QStash will use the app’s URL. However, for local development, you have two main options: use a local QStash server or set up a local tunnel.
To start the local QStash server, run:
Once the command runs successfully, you’ll see QSTASH_URL
and QSTASH_TOKEN
values in the console. Add these values to your .dev.vars
file:
This approach allows you to test workflows locally without affecting your billing. However, runs won’t be logged in the Upstash Console.
Alternatively, you can set up a local tunnel. For this option:
QSTASH_TOKEN
from the Upstash Console..dev.vars
file with the following:***
with your actual QStash token.UPSTASH_WORKFLOW_URL
to the public URL provided by your local tunnel.Here’s where you can find your QStash token:
Using a local tunnel connects your endpoint to the production QStash, enabling you to view workflow logs in the Upstash Console.
A workflow endpoint allows you to define a set of steps that, together, make up a workflow. Each step contains a piece of business logic that is automatically retried on failure, with easy monitoring via our visual workflow dashboard.
To define a workflow endpoint with Cloudflare Workers, navigate into your workers entrypoint file (usually src/index.ts
) and add the following code:
To start your worker locally, run the following command:
Executing this command prints a local URL to your workflow endpoint. By default, this URL is http://localhost:8787
.
You can verify your correct environment variable setup by checking the wrangler output, which should now have access to your QSTASH_TOKEN
binding and log your local URL:
Then, make a POST request to your workflow endpoint. For each workflow run, a unique workflow run ID is returned:
See the documentation on starting a workflow for other ways you can start your workflow.
If you didn’t set up local QStash development server, you can use this ID to track the workflow run and see its status in your QStash workflow dashboard. All steps are listed with their statuses, headers, and body for a detailed overview of your workflow from start to finish. Click on a step to see its detailed logs.
When deploying your Cloudflare Worker with Upstash Workflow to production, there are a few key points to keep in mind:
Environment Variables: Make sure that all necessary environment variables from your .dev.vars
file are set in your Cloudflare Worker project settings. For example, your QSTASH_TOKEN
, ENVIRONMENT
, and any other configuration variables your workflow might need.
Remove Local Development Settings: In your production code, you can remove or conditionally exclude any local development settings. For example, if you used local tunnel for local development
Deployment: Deploy your Cloudflare Worker to production as you normally would, for example using the Cloudflare CLI:
Verify Workflow Endpoint: After deployment, verify that your workflow endpoint is accessible by making a POST request to your production URL:
Monitor in QStash Dashboard: Use the QStash dashboard to monitor your production workflows. You can track workflow runs, view step statuses, and access detailed logs.
Set Up Alerts: Consider setting up alerts in Sentry or other monitoring tools to be notified of any workflow failures in production.
Learn how to protect your workflow endpoint from unauthorized access by securing your workflow endpoint.
Explore the source code for a detailed, end-to-end example and best practices.
For setting up and testing your workflows in a local environment, check out our local development guide.
You can find the project source code on GitHub.
Deploy the project to Cloudflare Workers with a single click.
This guide provides detailed, step-by-step instructions on how to use and deploy Upstash Workflow with Cloudflare Workers. You can also explore our Cloudflare Workers example or Hono.js Cloudflare Workers example for detailed, end-to-end examples and best practices.
If you haven’t obtained your QStash API key yet, you can do so by signing up for an Upstash account and navigating to your QStash dashboard.
First, install the Workflow SDK in your worker project:
Create a .dev.vars
file in your project root and add your QStash token. This key is used to authenticate your application with the QStash service.
Upstash Workflow is powered by QStash, which requires access to your endpoint to execute workflows. When your app is deployed, QStash will use the app’s URL. However, for local development, you have two main options: use a local QStash server or set up a local tunnel.
To start the local QStash server, run:
Once the command runs successfully, you’ll see QSTASH_URL
and QSTASH_TOKEN
values in the console. Add these values to your .dev.vars
file:
This approach allows you to test workflows locally without affecting your billing. However, runs won’t be logged in the Upstash Console.
Alternatively, you can set up a local tunnel. For this option:
QSTASH_TOKEN
from the Upstash Console..dev.vars
file with the following:***
with your actual QStash token.UPSTASH_WORKFLOW_URL
to the public URL provided by your local tunnel.Here’s where you can find your QStash token:
Using a local tunnel connects your endpoint to the production QStash, enabling you to view workflow logs in the Upstash Console.
A workflow endpoint allows you to define a set of steps that, together, make up a workflow. Each step contains a piece of business logic that is automatically retried on failure, with easy monitoring via our visual workflow dashboard.
To define a workflow endpoint with Cloudflare Workers, navigate into your workers entrypoint file (usually src/index.ts
) and add the following code:
To start your worker locally, run the following command:
Executing this command prints a local URL to your workflow endpoint. By default, this URL is http://localhost:8787
.
You can verify your correct environment variable setup by checking the wrangler output, which should now have access to your QSTASH_TOKEN
binding and log your local URL:
Then, make a POST request to your workflow endpoint. For each workflow run, a unique workflow run ID is returned:
See the documentation on starting a workflow for other ways you can start your workflow.
If you didn’t set up local QStash development server, you can use this ID to track the workflow run and see its status in your QStash workflow dashboard. All steps are listed with their statuses, headers, and body for a detailed overview of your workflow from start to finish. Click on a step to see its detailed logs.
When deploying your Cloudflare Worker with Upstash Workflow to production, there are a few key points to keep in mind:
Environment Variables: Make sure that all necessary environment variables from your .dev.vars
file are set in your Cloudflare Worker project settings. For example, your QSTASH_TOKEN
, ENVIRONMENT
, and any other configuration variables your workflow might need.
Remove Local Development Settings: In your production code, you can remove or conditionally exclude any local development settings. For example, if you used local tunnel for local development
Deployment: Deploy your Cloudflare Worker to production as you normally would, for example using the Cloudflare CLI:
Verify Workflow Endpoint: After deployment, verify that your workflow endpoint is accessible by making a POST request to your production URL:
Monitor in QStash Dashboard: Use the QStash dashboard to monitor your production workflows. You can track workflow runs, view step statuses, and access detailed logs.
Set Up Alerts: Consider setting up alerts in Sentry or other monitoring tools to be notified of any workflow failures in production.
Learn how to protect your workflow endpoint from unauthorized access by securing your workflow endpoint.
Explore the source code for a detailed, end-to-end example and best practices.
For setting up and testing your workflows in a local environment, check out our local development guide.