@upstash/workflow 1.4.0 → 1.5.1-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/astro.d.mts +19 -2
- package/astro.d.ts +19 -2
- package/astro.js +670 -159
- package/astro.mjs +1 -1
- package/{chunk-DRHEHWMS.mjs → chunk-J3PXPHSB.mjs} +828 -317
- package/cloudflare.d.mts +17 -2
- package/cloudflare.d.ts +17 -2
- package/cloudflare.js +670 -159
- package/cloudflare.mjs +1 -1
- package/docs/agents/examples.mdx +8 -0
- package/docs/agents/features.mdx +375 -0
- package/docs/agents/getting-started.mdx +139 -0
- package/docs/agents/overview.mdx +40 -0
- package/docs/agents/patterns/evaluator-optimizer.mdx +72 -0
- package/docs/agents/patterns/orchestrator-workers.mdx +95 -0
- package/docs/agents/patterns/parallelization.mdx +77 -0
- package/docs/agents/patterns/prompt-chaining.mdx +84 -0
- package/docs/basics/best-practices/at-least-one-step.mdx +57 -0
- package/docs/basics/best-practices/business-logic-in-steps.mdx +52 -0
- package/docs/basics/best-practices/deterministic-code.mdx +132 -0
- package/docs/basics/best-practices/idempotency.mdx +38 -0
- package/docs/basics/best-practices/nested-context-methods.mdx +38 -0
- package/docs/basics/best-practices/overview.mdx +35 -0
- package/docs/basics/best-practices/promise-any.mdx +9 -0
- package/docs/basics/best-practices/return-step-results.mdx +80 -0
- package/docs/basics/best-practices/workflow-limits.mdx +62 -0
- package/docs/basics/client/cancel.mdx +137 -0
- package/docs/basics/client/dlq/callback.mdx +21 -0
- package/docs/basics/client/dlq/delete.mdx +120 -0
- package/docs/basics/client/dlq/list.mdx +96 -0
- package/docs/basics/client/dlq/restart.mdx +164 -0
- package/docs/basics/client/dlq/resume.mdx +167 -0
- package/docs/basics/client/logs.mdx +139 -0
- package/docs/basics/client/notify.mdx +79 -0
- package/docs/basics/client/trigger.mdx +139 -0
- package/docs/basics/client/waiters.mdx +31 -0
- package/docs/basics/client.mdx +40 -0
- package/docs/basics/how.mdx +65 -0
- package/docs/basics/serve/advanced.mdx +435 -0
- package/docs/basics/serve.mdx +142 -0
- package/docs/changelog.mdx +174 -0
- package/docs/examples/allInOne.mdx +377 -0
- package/docs/examples/authWebhook.mdx +575 -0
- package/docs/examples/customRetry.mdx +309 -0
- package/docs/examples/customerOnboarding.mdx +230 -0
- package/docs/examples/dynamicWorkflow.mdx +203 -0
- package/docs/examples/eCommerceOrderFulfillment.mdx +281 -0
- package/docs/examples/imageProcessing.mdx +339 -0
- package/docs/examples/paymentRetry.mdx +438 -0
- package/docs/examples/waitForEvent.mdx +201 -0
- package/docs/features/dlq/callback.mdx +42 -0
- package/docs/features/dlq/delete.mdx +29 -0
- package/docs/features/dlq/restart.mdx +33 -0
- package/docs/features/dlq/resume.mdx +37 -0
- package/docs/features/dlq.mdx +39 -0
- package/docs/features/failure-callback.mdx +102 -0
- package/docs/features/failureFunction/advanced.mdx +36 -0
- package/docs/features/failureFunction/reliability.mdx +33 -0
- package/docs/features/flow-control/monitor.mdx +22 -0
- package/docs/features/flow-control/parallelism.mdx +45 -0
- package/docs/features/flow-control/rate-period.mdx +46 -0
- package/docs/features/flow-control.mdx +164 -0
- package/docs/features/invoke/serveMany.mdx +109 -0
- package/docs/features/invoke.mdx +39 -0
- package/docs/features/notify.mdx +127 -0
- package/docs/features/parallel-steps.mdx +41 -0
- package/docs/features/retries/prevent-retries.mdx +140 -0
- package/docs/features/retries.mdx +93 -0
- package/docs/features/wait-for-event.mdx +104 -0
- package/docs/features/wait.mdx +44 -0
- package/docs/features/webhooks.mdx +116 -0
- package/docs/getstarted.mdx +200 -0
- package/docs/howto/cancel.mdx +50 -0
- package/docs/howto/changes.mdx +33 -0
- package/docs/howto/configure.mdx +42 -0
- package/docs/howto/failures.mdx +185 -0
- package/docs/howto/get-token.mdx +18 -0
- package/docs/howto/local-development/development-server.mdx +130 -0
- package/docs/howto/local-development/local-tunnel.mdx +73 -0
- package/docs/howto/middlewares.mdx +263 -0
- package/docs/howto/migrations.mdx +335 -0
- package/docs/howto/multi-region.mdx +107 -0
- package/docs/howto/parallel-runs.mdx +52 -0
- package/docs/howto/readonly-token.mdx +19 -0
- package/docs/howto/realtime/basic.mdx +315 -0
- package/docs/howto/realtime/human-in-the-loop.mdx +454 -0
- package/docs/howto/redact-fields.mdx +61 -0
- package/docs/howto/retry-now.mdx +41 -0
- package/docs/howto/schedule.mdx +114 -0
- package/docs/howto/security.mdx +143 -0
- package/docs/howto/singleton.mdx +137 -0
- package/docs/howto/start.mdx +69 -0
- package/docs/howto/use-webhooks.mdx +256 -0
- package/docs/integrations/aisdk.mdx +316 -0
- package/docs/integrations/anthropic.mdx +51 -0
- package/docs/integrations/datadog.mdx +69 -0
- package/docs/integrations/openai.mdx +87 -0
- package/docs/integrations/prometheus.mdx +65 -0
- package/docs/integrations/resend.mdx +82 -0
- package/docs/llms-txt.mdx +4 -0
- package/docs/openapi.yaml +2946 -0
- package/docs/pricing.mdx +22 -0
- package/docs/quickstarts/astro.mdx +185 -0
- package/docs/quickstarts/cloudflare-workers.mdx +190 -0
- package/docs/quickstarts/express.mdx +190 -0
- package/docs/quickstarts/fastapi.mdx +282 -0
- package/docs/quickstarts/flask.mdx +282 -0
- package/docs/quickstarts/hono.mdx +221 -0
- package/docs/quickstarts/nextjs-fastapi.mdx +147 -0
- package/docs/quickstarts/nextjs-flask.mdx +147 -0
- package/docs/quickstarts/nuxt.mdx +169 -0
- package/docs/quickstarts/platforms.mdx +78 -0
- package/docs/quickstarts/solidjs.mdx +161 -0
- package/docs/quickstarts/svelte.mdx +170 -0
- package/docs/quickstarts/tanstack-start.mdx +205 -0
- package/docs/quickstarts/vercel-nextjs.mdx +233 -0
- package/docs/roadmap.mdx +8 -0
- package/docs/sdk/workflow-js.mdx +4 -0
- package/docs/sdk/workflow-py.mdx +4 -0
- package/docs/steps/api.mdx +64 -0
- package/docs/steps/call.mdx +183 -0
- package/docs/steps/cancel.mdx +25 -0
- package/docs/steps/createWebhook.mdx +40 -0
- package/docs/steps/invoke.mdx +100 -0
- package/docs/steps/notify.mdx +105 -0
- package/docs/steps/run.mdx +150 -0
- package/docs/steps/sleep.mdx +97 -0
- package/docs/steps/sleepUntil.mdx +88 -0
- package/docs/steps/waitForEvent.mdx +60 -0
- package/docs/steps/waitForWebhook.mdx +78 -0
- package/docs/steps.mdx +108 -0
- package/docs/troubleshooting/general.mdx +331 -0
- package/docs/troubleshooting/vercel.mdx +82 -0
- package/express.d.mts +19 -2
- package/express.d.ts +19 -2
- package/express.js +670 -159
- package/express.mjs +1 -1
- package/h3.d.mts +19 -2
- package/h3.d.ts +19 -2
- package/h3.js +670 -159
- package/h3.mjs +1 -1
- package/hono.d.mts +17 -2
- package/hono.d.ts +17 -2
- package/hono.js +670 -159
- package/hono.mjs +1 -1
- package/index.d.mts +50 -21
- package/index.d.ts +50 -21
- package/index.js +686 -171
- package/index.mjs +17 -13
- package/nextjs.d.mts +40 -2
- package/nextjs.d.ts +40 -2
- package/nextjs.js +670 -159
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/react-router.d.mts +16 -2
- package/react-router.d.ts +16 -2
- package/react-router.js +670 -159
- package/react-router.mjs +1 -1
- package/{serve-many-CG3BFvO3.d.mts → serve-many-BKukvLNl.d.mts} +1 -1
- package/{serve-many-iJF1IUXk.d.ts → serve-many-CrLKQpuZ.d.ts} +1 -1
- package/solidjs.d.mts +10 -1
- package/solidjs.d.ts +10 -1
- package/solidjs.js +670 -159
- package/solidjs.mjs +1 -1
- package/src/platforms/astro.ts +84 -0
- package/src/platforms/cloudflare.ts +127 -0
- package/src/platforms/express.ts +147 -0
- package/src/platforms/h3.ts +105 -0
- package/src/platforms/hono.ts +103 -0
- package/src/platforms/nextjs.ts +193 -0
- package/src/platforms/react-router.ts +92 -0
- package/src/platforms/solidjs.ts +59 -0
- package/src/platforms/svelte.ts +99 -0
- package/src/platforms/tanstack.ts +96 -0
- package/src/src/client/dlq.ts +387 -0
- package/src/src/client/filter-types.ts +166 -0
- package/src/src/client/index.ts +350 -0
- package/src/src/client/types.ts +501 -0
- package/src/src/client/utils.ts +307 -0
- package/src/src/constants.ts +82 -0
- package/src/src/context/api/anthropic.ts +58 -0
- package/src/src/context/api/base.ts +52 -0
- package/src/src/context/api/index.ts +24 -0
- package/src/src/context/api/openai.ts +125 -0
- package/src/src/context/api/resend.ts +57 -0
- package/src/src/context/auto-executor.ts +707 -0
- package/src/src/context/context.ts +681 -0
- package/src/src/context/index.ts +1 -0
- package/src/src/context/provider.ts +37 -0
- package/src/src/context/steps.ts +965 -0
- package/src/src/error.ts +203 -0
- package/src/src/index.ts +13 -0
- package/src/src/middleware/default-callbacks.ts +20 -0
- package/src/src/middleware/index.ts +2 -0
- package/src/src/middleware/logging.ts +39 -0
- package/src/src/middleware/manager.ts +148 -0
- package/src/src/middleware/middleware.ts +46 -0
- package/src/src/middleware/types.ts +72 -0
- package/src/src/qstash/headers.ts +397 -0
- package/src/src/qstash/step-config.ts +268 -0
- package/src/src/qstash/submit-steps.ts +284 -0
- package/src/src/serve/authorization.ts +118 -0
- package/src/src/serve/index.ts +475 -0
- package/src/src/serve/multi-region/handlers.ts +225 -0
- package/src/src/serve/multi-region/utils.ts +88 -0
- package/src/src/serve/options.ts +241 -0
- package/src/src/serve/serve-many.ts +117 -0
- package/src/src/serve/utils.ts +11 -0
- package/src/src/types.ts +590 -0
- package/src/src/utils.ts +141 -0
- package/src/src/workflow-parser.ts +472 -0
- package/src/src/workflow-requests.ts +575 -0
- package/svelte.d.mts +17 -2
- package/svelte.d.ts +17 -2
- package/svelte.js +670 -159
- package/svelte.mjs +1 -1
- package/tanstack.d.mts +15 -2
- package/tanstack.d.ts +15 -2
- package/tanstack.js +670 -159
- package/tanstack.mjs +1 -1
- package/{types-CekOpKvz.d.ts → types-CrgK5P6p.d.mts} +372 -32
- package/{types-CekOpKvz.d.mts → types-CrgK5P6p.d.ts} +372 -32
package/docs/pricing.mdx
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Upstash Workflow Pricing
|
|
3
|
+
sidebarTitle: "Pricing"
|
|
4
|
+
---
|
|
5
|
+
Upstash Workflow is based on QStash and uses a "pay-as-you-go" pricing model. You only incur costs when your app receives traffic, meaning there's no charge when it's not in use. Click [here](https://upstash.com/pricing/workflow) to view the pricing.
|
|
6
|
+
|
|
7
|
+
A workflow run consists of several QStash messages, with the total cost determined by the number of messages used.
|
|
8
|
+
|
|
9
|
+
You can track your current message usage and associated costs in the [Overview tab of the console](https://console.upstash.com/qstash?tab=details).
|
|
10
|
+
|
|
11
|
+
<Frame>
|
|
12
|
+
<img src="/img/qstash/message_cost.png" alt="Workflow message cost diagram" />
|
|
13
|
+
</Frame>
|
|
14
|
+
|
|
15
|
+
For detailed pricing information based on different plans, visit our [Workflow pricing page](https://upstash.com/pricing/workflow).
|
|
16
|
+
|
|
17
|
+
### Message Usage per Workflow Run
|
|
18
|
+
|
|
19
|
+
- [context.run](/workflow/steps/run), [context.sleep](/workflow/steps/sleep), [context.sleepUntil](/workflow/steps/sleepUntil), or [context.waitForEvent](/workflow/steps/waitForEvent) commands generate a single message.
|
|
20
|
+
- The [context.call](/workflow/steps/call) command generates two messages.
|
|
21
|
+
- Each step in a [parallel run](/workflow/howto/parallel-runs) costs 1 extra message.
|
|
22
|
+
- If the workflow endpoint or URL in [context.call](/workflow/steps/call) returns an error or is unreachable, the workflow SDK will retry the call (up to 3 times by default). Each retry counts as a new message.
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Upstash Workflow with Astro
|
|
3
|
+
sidebarTitle: Astro
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<Card
|
|
7
|
+
title="GitHub Repository"
|
|
8
|
+
icon="github"
|
|
9
|
+
href="https://github.com/upstash/workflow-js/tree/main/examples/astro"
|
|
10
|
+
horizontal
|
|
11
|
+
>
|
|
12
|
+
You can find the project source code on GitHub.
|
|
13
|
+
</Card>
|
|
14
|
+
<Card title="Deploy With Vercel" icon="triangle" iconType="sharp-solid" href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fupstash%2Fworkflow-js%2Ftree%2Fmain%2Fexamples%2Fastro&env=QSTASH_TOKEN&envDescription=You%20can%20access%20this%20variable%20from%20Upstash%20Console%2C%20under%20QStash%20page.%20&project-name=workflow-astro&repository-name=workflow-astro&demo-title=Upstash%20Workflow%20Example&demo-description=A%20Astro%20application%20utilizing%20Upstash%20Workflows" horizontal>
|
|
15
|
+
Deploy the project to Vercel with a single click.
|
|
16
|
+
</Card>
|
|
17
|
+
This guide provides detailed, step-by-step instructions on how to use and deploy
|
|
18
|
+
Upstash Workflow with Astro. You can also explore [the source code](https://github.com/upstash/workflow-js/tree/main/examples/astro)
|
|
19
|
+
for a detailed, end-to-end example and best practices.
|
|
20
|
+
|
|
21
|
+
## Prerequisites
|
|
22
|
+
|
|
23
|
+
1. An Upstash QStash API key.
|
|
24
|
+
2. Node.js and npm (another package manager) installed.
|
|
25
|
+
|
|
26
|
+
If you haven't obtained your QStash API key yet, you can do so by [signing up](https://console.upstash.com/auth/sign-in) for an Upstash account and navigating to your QStash dashboard.
|
|
27
|
+
|
|
28
|
+
## Step 1: Installation
|
|
29
|
+
|
|
30
|
+
First, install the Workflow SDK in your Astro project:
|
|
31
|
+
|
|
32
|
+
<CodeGroup>
|
|
33
|
+
```bash npm
|
|
34
|
+
npm install @upstash/workflow
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```bash pnpm
|
|
38
|
+
pnpm install @upstash/workflow
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```bash bun
|
|
42
|
+
bun add @upstash/workflow
|
|
43
|
+
```
|
|
44
|
+
</CodeGroup>
|
|
45
|
+
|
|
46
|
+
## Step 2: Configure Environment Variables
|
|
47
|
+
|
|
48
|
+
Create a `.env` file in your project root and add your QStash token. This key is used to authenticate your application with the QStash service.
|
|
49
|
+
|
|
50
|
+
```bash Terminal
|
|
51
|
+
touch .env
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Upstash Workflow is powered by [QStash](/qstash/overall/getstarted), 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](/workflow/howto/local-development/development-server).
|
|
55
|
+
|
|
56
|
+
### Option 1: Development Server
|
|
57
|
+
|
|
58
|
+
Since you are using `@upstash/workflow`, you can set `QSTASH_DEV=true` in your `.env` file. The SDK then downloads and connects to the local QStash development server automatically — no tokens or signing keys to copy over:
|
|
59
|
+
|
|
60
|
+
```txt .env
|
|
61
|
+
QSTASH_DEV=true
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Both the workflow client and the `serve()` endpoint pick up the dev server automatically, including signature verification. This lets you test workflows locally without affecting your billing.
|
|
65
|
+
|
|
66
|
+
For ports, the `registerQStashDev()` helper, and other details, see the [Development Server guide](/workflow/howto/local-development/development-server).
|
|
67
|
+
|
|
68
|
+
### Option 2: Local Tunnel
|
|
69
|
+
|
|
70
|
+
Alternatively, you can set up a local tunnel. For this option:
|
|
71
|
+
|
|
72
|
+
1. Copy the `QSTASH_TOKEN` from the Upstash Console (see [Get your QStash Token](/workflow/howto/get-token)).
|
|
73
|
+
2. Update your `.env` file with the following:
|
|
74
|
+
|
|
75
|
+
```txt
|
|
76
|
+
QSTASH_TOKEN="***"
|
|
77
|
+
UPSTASH_WORKFLOW_URL="<UPSTASH_WORKFLOW_URL>"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- Replace `***` with your actual QStash token.
|
|
81
|
+
- Set `UPSTASH_WORKFLOW_URL` to the public URL provided by your local tunnel.
|
|
82
|
+
|
|
83
|
+
Here’s where you can find your QStash token:
|
|
84
|
+
|
|
85
|
+
<Frame>
|
|
86
|
+
<img src="/img/qstash-workflow/console-quickstart-env.jpg" alt="QStash environment variables in the Upstash Console" />
|
|
87
|
+
</Frame>
|
|
88
|
+
|
|
89
|
+
Using a local tunnel connects your endpoint to the production QStash, enabling you to view workflow logs in the Upstash Console.
|
|
90
|
+
|
|
91
|
+
## Step 3: Create a Workflow Endpoint
|
|
92
|
+
|
|
93
|
+
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.
|
|
94
|
+
|
|
95
|
+
To define a workflow endpoint with Astro, navigate into your entrypoint file (usually `src/index.ts`) and add the following code:
|
|
96
|
+
|
|
97
|
+
<Tabs>
|
|
98
|
+
<Tab title="Minimal example">
|
|
99
|
+
```typescript src/pages/api/workflow.ts
|
|
100
|
+
import { serve } from "@upstash/workflow/astro";
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
export const { POST } = serve<string>(async (context) => {
|
|
104
|
+
const result1 = await context.run("initial-step", () => {
|
|
105
|
+
console.log("initial step ran")
|
|
106
|
+
return "hello world!"
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
await context.run("second-step", () => {
|
|
110
|
+
console.log(`second step ran with value ${result1}`)
|
|
111
|
+
})
|
|
112
|
+
}, {
|
|
113
|
+
// env must be passed in astro.
|
|
114
|
+
// for local dev, we need import.meta.env.
|
|
115
|
+
// For deployment, we need process.env:
|
|
116
|
+
env: {
|
|
117
|
+
...process.env,
|
|
118
|
+
...import.meta.env
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
````
|
|
123
|
+
</Tab>
|
|
124
|
+
</Tabs>
|
|
125
|
+
|
|
126
|
+
## Step 4: Run the Workflow Endpoint
|
|
127
|
+
|
|
128
|
+
After defining the endpoint, you can trigger your workflow by starting your app:
|
|
129
|
+
|
|
130
|
+
```bash Terminal
|
|
131
|
+
npm run dev
|
|
132
|
+
````
|
|
133
|
+
|
|
134
|
+
Then, make a POST request to your workflow endpoint. For each workflow run, a unique workflow run ID is returned:
|
|
135
|
+
|
|
136
|
+
```bash Terminal
|
|
137
|
+
curl -X POST http://localhost:3000/api/workflow \
|
|
138
|
+
-H "Content-Type: application/json" \
|
|
139
|
+
-d '{"message": "Hello from the workflow!"}'
|
|
140
|
+
|
|
141
|
+
# result: {"workflowRunId":"wfr_xxxxxx"}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
See the [documentation on starting a workflow](/workflow/howto/start) for other ways you can start your workflow.
|
|
145
|
+
|
|
146
|
+
<Frame>
|
|
147
|
+
<img src="/img/qstash-workflow/hono_local_request.png" alt="Local workflow request" />
|
|
148
|
+
</Frame>
|
|
149
|
+
|
|
150
|
+
If you are using a local tunnel, 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.
|
|
151
|
+
|
|
152
|
+
<Frame>
|
|
153
|
+
<img src="/img/qstash-workflow/dashboard.png" alt="Workflow run in the Upstash Console" />
|
|
154
|
+
</Frame>
|
|
155
|
+
|
|
156
|
+
## Step 5: Deploying to Production
|
|
157
|
+
|
|
158
|
+
When deploying your Astro app with Upstash Workflow to production, there are a few key points to keep in mind:
|
|
159
|
+
|
|
160
|
+
1. **Environment Variables**: Make sure that all necessary environment variables from your `.env` file are set in your Vercel project settings. For example, your `QSTASH_TOKEN`, and any other configuration variables your workflow might need.
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
2. **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](/workflow/howto/local-development/local-tunnel)
|
|
164
|
+
|
|
165
|
+
3. **Deployment**: Deploy your Astro app to production as you normally would, for example to Vercel or AWS.
|
|
166
|
+
|
|
167
|
+
4. **Verify Workflow Endpoint**: After deployment, verify that your workflow endpoint is accessible by making a POST request to your production URL:
|
|
168
|
+
|
|
169
|
+
```bash Terminal
|
|
170
|
+
curl -X POST <DEPLOYMENT_URL>/api/workflow \
|
|
171
|
+
-H "Content-Type: application/json" \
|
|
172
|
+
-d '{"message": "Hello from the workflow!"}'
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
5. **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.
|
|
176
|
+
|
|
177
|
+
6. **Set Up Alerts**: Consider setting up alerts in Sentry or other monitoring tools to be notified of any workflow failures in production.
|
|
178
|
+
|
|
179
|
+
## Next Steps
|
|
180
|
+
|
|
181
|
+
1. Learn how to protect your workflow endpoint from unauthorized access by [securing your workflow endpoint](/workflow/howto/security).
|
|
182
|
+
|
|
183
|
+
2. Explore [the source code](https://github.com/upstash/workflow-js/tree/main/examples/astro) for a detailed, end-to-end example and best practices.
|
|
184
|
+
|
|
185
|
+
3. For setting up and testing your workflows in a local environment, check out our [local development guide](/workflow/howto/local-development/development-server).
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Upstash Workflow with Cloudflare Workers
|
|
3
|
+
sidebarTitle: "Cloudflare Workers"
|
|
4
|
+
---
|
|
5
|
+
<Card title="GitHub Repository" icon="github" href="https://github.com/upstash/workflow-js/tree/main/examples/cloudflare-workers" horizontal>
|
|
6
|
+
You can find the project source code on GitHub.
|
|
7
|
+
</Card>
|
|
8
|
+
<Card title="Deploy With Cloudflare Workers" icon="cloudflare" href="https://deploy.workers.cloudflare.com/?url=https://github.com/upstash/qstash-workflow-example-cloudflare-workers" horizontal>
|
|
9
|
+
Deploy the project to Cloudflare Workers with a single click.
|
|
10
|
+
</Card>
|
|
11
|
+
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](https://github.com/upstash/workflow-js/tree/main/examples/cloudflare-workers) or [Hono.js Cloudflare Workers example](https://github.com/upstash/workflow-js/tree/main/examples/cloudflare-workers-hono) for detailed, end-to-end examples and best practices.
|
|
12
|
+
|
|
13
|
+
## Prerequisites
|
|
14
|
+
|
|
15
|
+
1. An Upstash QStash API key.
|
|
16
|
+
2. Node.js and npm (another package manager) installed.
|
|
17
|
+
|
|
18
|
+
If you haven't obtained your QStash API key yet, you can do so by [signing up](https://console.upstash.com/auth/sign-in) for an Upstash account and navigating to your QStash dashboard.
|
|
19
|
+
|
|
20
|
+
## Step 1: Installation
|
|
21
|
+
|
|
22
|
+
First, install the Workflow SDK in your worker project:
|
|
23
|
+
|
|
24
|
+
<Tabs>
|
|
25
|
+
<Tab title="npm">
|
|
26
|
+
```bash
|
|
27
|
+
npm install @upstash/workflow
|
|
28
|
+
```
|
|
29
|
+
</Tab>
|
|
30
|
+
<Tab title="pnpm">
|
|
31
|
+
```bash
|
|
32
|
+
pnpm install @upstash/workflow
|
|
33
|
+
```
|
|
34
|
+
</Tab>
|
|
35
|
+
<Tab title="bun">
|
|
36
|
+
```bash
|
|
37
|
+
bun add @upstash/workflow
|
|
38
|
+
```
|
|
39
|
+
</Tab>
|
|
40
|
+
</Tabs>
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## Step 2: Configure Environment Variables
|
|
44
|
+
|
|
45
|
+
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.
|
|
46
|
+
|
|
47
|
+
```bash Terminal
|
|
48
|
+
touch .dev.vars
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Upstash Workflow is powered by [QStash](/qstash/overall/getstarted), 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](/workflow/howto/local-development/development-server).
|
|
52
|
+
|
|
53
|
+
### Option 1: Local QStash Server
|
|
54
|
+
|
|
55
|
+
To start the local QStash server, run:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npx @upstash/qstash-cli dev
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
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:
|
|
62
|
+
|
|
63
|
+
```txt .dev.vars
|
|
64
|
+
QSTASH_URL="http://127.0.0.1:8080"
|
|
65
|
+
QSTASH_TOKEN="<QSTASH_TOKEN>"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
This approach allows you to test workflows locally without affecting your billing. However, runs won't be logged in the Upstash Console.
|
|
69
|
+
|
|
70
|
+
### Option 2: Local Tunnel
|
|
71
|
+
|
|
72
|
+
Alternatively, you can set up a local tunnel. For this option:
|
|
73
|
+
|
|
74
|
+
1. Copy the `QSTASH_TOKEN` from the Upstash Console (see [Get your QStash Token](/workflow/howto/get-token)).
|
|
75
|
+
2. Update your `.dev.vars` file with the following:
|
|
76
|
+
|
|
77
|
+
```txt .dev.vars
|
|
78
|
+
QSTASH_TOKEN="***"
|
|
79
|
+
UPSTASH_WORKFLOW_URL="<UPSTASH_WORKFLOW_URL>"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- Replace `***` with your actual QStash token.
|
|
83
|
+
- Set `UPSTASH_WORKFLOW_URL` to the public URL provided by your local tunnel.
|
|
84
|
+
|
|
85
|
+
Here’s where you can find your QStash token:
|
|
86
|
+
|
|
87
|
+
<Frame>
|
|
88
|
+
<img src="/img/qstash-workflow/console-quickstart-env.jpg" alt="QStash environment variables in the Upstash Console" />
|
|
89
|
+
</Frame>
|
|
90
|
+
|
|
91
|
+
Using a local tunnel connects your endpoint to the production QStash, enabling you to view workflow logs in the Upstash Console.
|
|
92
|
+
|
|
93
|
+
## Step 3: Create a Workflow Endpoint
|
|
94
|
+
|
|
95
|
+
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.
|
|
96
|
+
|
|
97
|
+
To define a workflow endpoint with Cloudflare Workers, navigate into your workers entrypoint file (usually `src/index.ts`) and add the following code:
|
|
98
|
+
|
|
99
|
+
```typescript src/index.ts
|
|
100
|
+
import { serve } from "@upstash/workflow/cloudflare"
|
|
101
|
+
|
|
102
|
+
interface Env {
|
|
103
|
+
ENVIRONMENT: "development" | "production"
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default serve<{ text: string }>(
|
|
107
|
+
async (context) => {
|
|
108
|
+
const initialPayload = context.requestPayload.text
|
|
109
|
+
|
|
110
|
+
const result = await context.run("initial-step", async () => {
|
|
111
|
+
console.log(`Step 1 running with payload: ${initialPayload}`)
|
|
112
|
+
|
|
113
|
+
return { text: "initial step ran" }
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
await context.run("second-step", async () => {
|
|
118
|
+
console.log(`Step 2 running with result from step 1: ${result.text}`)
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Step 4: Run the Workflow Endpoint
|
|
125
|
+
|
|
126
|
+
To start your worker locally, run the following command:
|
|
127
|
+
|
|
128
|
+
```bash Terminal
|
|
129
|
+
npm run wrangler dev
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Executing this command prints a local URL to your workflow endpoint. By default, this URL is `http://localhost:8787`.
|
|
133
|
+
|
|
134
|
+
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:
|
|
135
|
+
|
|
136
|
+
<Frame>
|
|
137
|
+
<img src="/img/qstash-workflow/wrangler.png" alt="Local Cloudflare Worker started with Wrangler" />
|
|
138
|
+
</Frame>
|
|
139
|
+
|
|
140
|
+
Then, make a POST request to your workflow endpoint. For each workflow run, a unique workflow run ID is returned:
|
|
141
|
+
|
|
142
|
+
```bash Terminal
|
|
143
|
+
curl -X POST https://localhost:8787/ -D '{"text": "hello world!"}'
|
|
144
|
+
|
|
145
|
+
# result: {"workflowRunId":"wfr_xxxxxx"}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
<Frame>
|
|
149
|
+
<img src="/img/qstash-workflow/workers_local_request.png" alt="Local Cloudflare Workers request" />
|
|
150
|
+
</Frame>
|
|
151
|
+
|
|
152
|
+
See the [documentation on starting a workflow](/workflow/howto/start) for other ways you can start your workflow.
|
|
153
|
+
|
|
154
|
+
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.
|
|
155
|
+
|
|
156
|
+
<Frame>
|
|
157
|
+
<img src="/img/qstash-workflow/dashboard.png" alt="Workflow run in the Upstash Console" />
|
|
158
|
+
</Frame>
|
|
159
|
+
|
|
160
|
+
## Step 5: Deploying to Production
|
|
161
|
+
|
|
162
|
+
When deploying your Cloudflare Worker with Upstash Workflow to production, there are a few key points to keep in mind:
|
|
163
|
+
|
|
164
|
+
1. **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.
|
|
165
|
+
|
|
166
|
+
2. **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](/workflow/howto/local-development/local-tunnel)
|
|
167
|
+
|
|
168
|
+
3. **Deployment**: Deploy your Cloudflare Worker to production as you normally would, for example using the Cloudflare CLI:
|
|
169
|
+
|
|
170
|
+
```bash Terminal
|
|
171
|
+
wrangler deploy
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
4. **Verify Workflow Endpoint**: After deployment, verify that your workflow endpoint is accessible by making a POST request to your production URL:
|
|
175
|
+
|
|
176
|
+
```bash Terminal
|
|
177
|
+
curl -X POST https://<YOUR-PRODUCTION-URL>/ -D '{"text": "hello world!"}'
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
5. **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.
|
|
181
|
+
|
|
182
|
+
6. **Set Up Alerts**: Consider setting up alerts in Sentry or other monitoring tools to be notified of any workflow failures in production.
|
|
183
|
+
|
|
184
|
+
## Next Steps
|
|
185
|
+
|
|
186
|
+
1. Learn how to protect your workflow endpoint from unauthorized access by [securing your workflow endpoint](/workflow/howto/security).
|
|
187
|
+
|
|
188
|
+
2. Explore [the source code](https://github.com/upstash/workflow-js/tree/main/examples/cloudflare-workers) for a detailed, end-to-end example and best practices.
|
|
189
|
+
|
|
190
|
+
3. For setting up and testing your workflows in a local environment, check out our [local development guide](/workflow/howto/local-development/development-server).
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Upstash Workflow with Express.js
|
|
3
|
+
sidebarTitle: Express.js
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<Card
|
|
7
|
+
title="GitHub Repository"
|
|
8
|
+
icon="github"
|
|
9
|
+
href="https://github.com/upstash/workflow-js/tree/main/examples/express"
|
|
10
|
+
horizontal
|
|
11
|
+
>
|
|
12
|
+
You can find the project source code on GitHub.
|
|
13
|
+
</Card>
|
|
14
|
+
This guide provides detailed, step-by-step instructions on how to use and deploy
|
|
15
|
+
Upstash Workflow with Express.js. You can also explore [the source code](https://github.com/upstash/workflow-js/tree/main/examples/express)
|
|
16
|
+
for a detailed, end-to-end example and best practices.
|
|
17
|
+
|
|
18
|
+
## Prerequisites
|
|
19
|
+
|
|
20
|
+
1. An Upstash QStash API key.
|
|
21
|
+
2. Node.js and npm (another package manager) installed.
|
|
22
|
+
|
|
23
|
+
If you haven't obtained your QStash API key yet, you can do so by [signing up](https://console.upstash.com/auth/sign-in) for an Upstash account and navigating to your QStash dashboard.
|
|
24
|
+
|
|
25
|
+
## Step 1: Installation
|
|
26
|
+
|
|
27
|
+
First, install the Workflow SDK in your Express.js project:
|
|
28
|
+
|
|
29
|
+
<Tabs>
|
|
30
|
+
<Tab title="npm">```bash npm install @upstash/workflow ```</Tab>
|
|
31
|
+
<Tab title="pnpm">```bash pnpm install @upstash/workflow ```</Tab>
|
|
32
|
+
<Tab title="bun">```bash bun add @upstash/workflow ```</Tab>
|
|
33
|
+
</Tabs>
|
|
34
|
+
|
|
35
|
+
## Step 2: Configure Environment Variables
|
|
36
|
+
|
|
37
|
+
Create a `.env` file in your project root and add your QStash token. This key is used to authenticate your application with the QStash service.
|
|
38
|
+
|
|
39
|
+
```bash Terminal
|
|
40
|
+
touch .env
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Upstash Workflow is powered by [QStash](/qstash/overall/getstarted), 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](/workflow/howto/local-development/development-server).
|
|
44
|
+
|
|
45
|
+
### Option 1: Development Server
|
|
46
|
+
|
|
47
|
+
Since you are using `@upstash/workflow`, you can set `QSTASH_DEV=true` in your `.env` file. The SDK then downloads and connects to the local QStash development server automatically — no tokens or signing keys to copy over:
|
|
48
|
+
|
|
49
|
+
```txt .env
|
|
50
|
+
QSTASH_DEV=true
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Both the workflow client and the `serve()` endpoint pick up the dev server automatically, including signature verification. This lets you test workflows locally without affecting your billing.
|
|
54
|
+
|
|
55
|
+
For ports, the `registerQStashDev()` helper, and other details, see the [Development Server guide](/workflow/howto/local-development/development-server).
|
|
56
|
+
|
|
57
|
+
### Option 2: Local Tunnel
|
|
58
|
+
|
|
59
|
+
Alternatively, you can set up a local tunnel. For this option:
|
|
60
|
+
|
|
61
|
+
1. Copy the `QSTASH_TOKEN` from the Upstash Console (see [Get your QStash Token](/workflow/howto/get-token)).
|
|
62
|
+
2. Update your `.env` file with the following:
|
|
63
|
+
|
|
64
|
+
```txt
|
|
65
|
+
QSTASH_TOKEN="***"
|
|
66
|
+
UPSTASH_WORKFLOW_URL="<UPSTASH_WORKFLOW_URL>"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- Replace `***` with your actual QStash token.
|
|
70
|
+
- Set `UPSTASH_WORKFLOW_URL` to the public URL provided by your local tunnel.
|
|
71
|
+
|
|
72
|
+
Here’s where you can find your QStash token:
|
|
73
|
+
|
|
74
|
+
<Frame>
|
|
75
|
+
<img src="/img/qstash-workflow/console-quickstart-env.jpg" alt="QStash environment variables in the Upstash Console" />
|
|
76
|
+
</Frame>
|
|
77
|
+
|
|
78
|
+
Using a local tunnel connects your endpoint to the production QStash, enabling you to view workflow logs in the Upstash Console.
|
|
79
|
+
|
|
80
|
+
## Step 3: Create a Workflow Endpoint
|
|
81
|
+
|
|
82
|
+
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.
|
|
83
|
+
|
|
84
|
+
To define a workflow endpoint with Express.js, navigate into your entrypoint file (usually `src/index.ts`) and add the following code:
|
|
85
|
+
|
|
86
|
+
<Tabs>
|
|
87
|
+
|
|
88
|
+
<Tab title="Minimal example">
|
|
89
|
+
```typescript src/index.ts
|
|
90
|
+
import { serve } from "@upstash/workflow/express";
|
|
91
|
+
import express from 'express';
|
|
92
|
+
import { config } from 'dotenv';
|
|
93
|
+
|
|
94
|
+
config();
|
|
95
|
+
|
|
96
|
+
const app = express();
|
|
97
|
+
|
|
98
|
+
app.use(
|
|
99
|
+
express.json()
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
app.post(
|
|
103
|
+
'/workflow',
|
|
104
|
+
serve<{ message: string }>(
|
|
105
|
+
async (context) => {
|
|
106
|
+
const res1 = await context.run("step1", async () => {
|
|
107
|
+
const message = context.requestPayload.message;
|
|
108
|
+
return message;
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
await context.run("step2", async () => {
|
|
112
|
+
console.log(res1);
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
app.listen(3000, () => {
|
|
119
|
+
console.log('Server running on port 3000');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
````
|
|
123
|
+
</Tab>
|
|
124
|
+
</Tabs>
|
|
125
|
+
|
|
126
|
+
## Step 4: Run the Workflow Endpoint
|
|
127
|
+
|
|
128
|
+
After defining the endpoint, you can trigger your workflow by starting your app:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm run dev
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Then make a POST request to your workflow endpoint. For each workflow run, a unique workflow run ID is returned:
|
|
135
|
+
|
|
136
|
+
```bash Terminal
|
|
137
|
+
curl -X POST http://localhost:3000/workflow \
|
|
138
|
+
-H "Content-Type: application/json" \
|
|
139
|
+
-d '{"message": "Hello from the workflow!"}'
|
|
140
|
+
|
|
141
|
+
# result: {"workflowRunId":"wfr_xxxxxx"}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
<Warning>
|
|
145
|
+
Express.js integration only works with `Content-Type: application/json`
|
|
146
|
+
header. Other payload types are not supported yet.
|
|
147
|
+
</Warning>
|
|
148
|
+
|
|
149
|
+
See the [documentation on starting a workflow](/workflow/howto/start) for other ways you can start your workflow.
|
|
150
|
+
|
|
151
|
+
<Frame>
|
|
152
|
+
<img src="/img/qstash-workflow/hono_local_request.png" alt="Local workflow request" />
|
|
153
|
+
</Frame>
|
|
154
|
+
|
|
155
|
+
If you are using a local tunnel, 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.
|
|
156
|
+
|
|
157
|
+
<Frame>
|
|
158
|
+
<img src="/img/qstash-workflow/dashboard.png" alt="Workflow run in the Upstash Console" />
|
|
159
|
+
</Frame>
|
|
160
|
+
|
|
161
|
+
## Step 5: Deploying to Production
|
|
162
|
+
|
|
163
|
+
When deploying your Hono app with Upstash Workflow to production, there are a few key points to keep in mind:
|
|
164
|
+
|
|
165
|
+
1. **Environment Variables**: Make sure that all necessary environment variables from your `.env` file are set in your Vercel project settings. For example, your `QSTASH_TOKEN`, and any other configuration variables your workflow might need.
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
2. **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](/workflow/howto/local-development/local-tunnel)
|
|
169
|
+
|
|
170
|
+
3. **Deployment**: Deploy your Express.js app to production as you normally would, for example to fly.io or AWS.
|
|
171
|
+
|
|
172
|
+
4. **Verify Workflow Endpoint**: After deployment, verify that your workflow endpoint is accessible by making a POST request to your production URL:
|
|
173
|
+
|
|
174
|
+
```bash Terminal
|
|
175
|
+
curl -X POST <DEPLOYMENT_URL>/workflow \
|
|
176
|
+
-H "Content-Type: application/json" \
|
|
177
|
+
-d '{"message": "Hello from the workflow!"}'
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
5. **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.
|
|
181
|
+
|
|
182
|
+
6. **Set Up Alerts**: Consider setting up alerts in Sentry or other monitoring tools to be notified of any workflow failures in production.
|
|
183
|
+
|
|
184
|
+
## Next Steps
|
|
185
|
+
|
|
186
|
+
1. Learn how to protect your workflow endpoint from unauthorized access by [securing your workflow endpoint](/workflow/howto/security).
|
|
187
|
+
|
|
188
|
+
2. Explore [the source code](https://github.com/upstash/workflow-js/tree/main/examples/express) for a detailed, end-to-end example and best practices.
|
|
189
|
+
|
|
190
|
+
3. For setting up and testing your workflows in a local environment, check out our [local development guide](/workflow/howto/local-development/development-server).
|