@upstash/workflow 1.4.0 → 1.5.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.
Files changed (223) hide show
  1. package/README.md +9 -0
  2. package/astro.d.mts +19 -2
  3. package/astro.d.ts +19 -2
  4. package/astro.js +670 -159
  5. package/astro.mjs +1 -1
  6. package/{chunk-DRHEHWMS.mjs → chunk-J3PXPHSB.mjs} +828 -317
  7. package/cloudflare.d.mts +17 -2
  8. package/cloudflare.d.ts +17 -2
  9. package/cloudflare.js +670 -159
  10. package/cloudflare.mjs +1 -1
  11. package/docs/agents/examples.mdx +8 -0
  12. package/docs/agents/features.mdx +374 -0
  13. package/docs/agents/getting-started.mdx +139 -0
  14. package/docs/agents/overview.mdx +40 -0
  15. package/docs/agents/patterns/evaluator-optimizer.mdx +72 -0
  16. package/docs/agents/patterns/orchestrator-workers.mdx +95 -0
  17. package/docs/agents/patterns/parallelization.mdx +77 -0
  18. package/docs/agents/patterns/prompt-chaining.mdx +84 -0
  19. package/docs/basics/best-practices/at-least-one-step.mdx +57 -0
  20. package/docs/basics/best-practices/business-logic-in-steps.mdx +52 -0
  21. package/docs/basics/best-practices/deterministic-code.mdx +132 -0
  22. package/docs/basics/best-practices/idempotency.mdx +38 -0
  23. package/docs/basics/best-practices/nested-context-methods.mdx +38 -0
  24. package/docs/basics/best-practices/overview.mdx +35 -0
  25. package/docs/basics/best-practices/promise-any.mdx +9 -0
  26. package/docs/basics/best-practices/return-step-results.mdx +80 -0
  27. package/docs/basics/best-practices/workflow-limits.mdx +62 -0
  28. package/docs/basics/client/cancel.mdx +137 -0
  29. package/docs/basics/client/dlq/callback.mdx +21 -0
  30. package/docs/basics/client/dlq/delete.mdx +120 -0
  31. package/docs/basics/client/dlq/list.mdx +96 -0
  32. package/docs/basics/client/dlq/restart.mdx +164 -0
  33. package/docs/basics/client/dlq/resume.mdx +167 -0
  34. package/docs/basics/client/logs.mdx +139 -0
  35. package/docs/basics/client/notify.mdx +79 -0
  36. package/docs/basics/client/trigger.mdx +139 -0
  37. package/docs/basics/client/waiters.mdx +31 -0
  38. package/docs/basics/client.mdx +40 -0
  39. package/docs/basics/how.mdx +65 -0
  40. package/docs/basics/serve/advanced.mdx +435 -0
  41. package/docs/basics/serve.mdx +142 -0
  42. package/docs/changelog.mdx +174 -0
  43. package/docs/examples/allInOne.mdx +377 -0
  44. package/docs/examples/authWebhook.mdx +567 -0
  45. package/docs/examples/customRetry.mdx +309 -0
  46. package/docs/examples/customerOnboarding.mdx +230 -0
  47. package/docs/examples/dynamicWorkflow.mdx +203 -0
  48. package/docs/examples/eCommerceOrderFulfillment.mdx +281 -0
  49. package/docs/examples/imageProcessing.mdx +339 -0
  50. package/docs/examples/paymentRetry.mdx +438 -0
  51. package/docs/examples/waitForEvent.mdx +201 -0
  52. package/docs/features/dlq/callback.mdx +42 -0
  53. package/docs/features/dlq/delete.mdx +29 -0
  54. package/docs/features/dlq/restart.mdx +33 -0
  55. package/docs/features/dlq/resume.mdx +37 -0
  56. package/docs/features/dlq.mdx +39 -0
  57. package/docs/features/failure-callback.mdx +102 -0
  58. package/docs/features/failureFunction/advanced.mdx +36 -0
  59. package/docs/features/failureFunction/reliability.mdx +33 -0
  60. package/docs/features/flow-control/monitor.mdx +22 -0
  61. package/docs/features/flow-control/parallelism.mdx +45 -0
  62. package/docs/features/flow-control/rate-period.mdx +46 -0
  63. package/docs/features/flow-control.mdx +164 -0
  64. package/docs/features/invoke/serveMany.mdx +109 -0
  65. package/docs/features/invoke.mdx +39 -0
  66. package/docs/features/notify.mdx +127 -0
  67. package/docs/features/parallel-steps.mdx +41 -0
  68. package/docs/features/retries/prevent-retries.mdx +140 -0
  69. package/docs/features/retries.mdx +93 -0
  70. package/docs/features/wait-for-event.mdx +104 -0
  71. package/docs/features/wait.mdx +44 -0
  72. package/docs/features/webhooks.mdx +116 -0
  73. package/docs/getstarted.mdx +200 -0
  74. package/docs/howto/cancel.mdx +50 -0
  75. package/docs/howto/changes.mdx +33 -0
  76. package/docs/howto/configure.mdx +42 -0
  77. package/docs/howto/failures.mdx +185 -0
  78. package/docs/howto/get-token.mdx +18 -0
  79. package/docs/howto/local-development/development-server.mdx +130 -0
  80. package/docs/howto/local-development/local-tunnel.mdx +73 -0
  81. package/docs/howto/middlewares.mdx +263 -0
  82. package/docs/howto/migrations.mdx +335 -0
  83. package/docs/howto/multi-region.mdx +107 -0
  84. package/docs/howto/parallel-runs.mdx +52 -0
  85. package/docs/howto/readonly-token.mdx +19 -0
  86. package/docs/howto/realtime/basic.mdx +315 -0
  87. package/docs/howto/realtime/human-in-the-loop.mdx +454 -0
  88. package/docs/howto/redact-fields.mdx +61 -0
  89. package/docs/howto/retry-now.mdx +41 -0
  90. package/docs/howto/schedule.mdx +104 -0
  91. package/docs/howto/security.mdx +143 -0
  92. package/docs/howto/singleton.mdx +137 -0
  93. package/docs/howto/start.mdx +69 -0
  94. package/docs/howto/use-webhooks.mdx +256 -0
  95. package/docs/integrations/aisdk.mdx +316 -0
  96. package/docs/integrations/anthropic.mdx +51 -0
  97. package/docs/integrations/datadog.mdx +69 -0
  98. package/docs/integrations/openai.mdx +87 -0
  99. package/docs/integrations/prometheus.mdx +65 -0
  100. package/docs/integrations/resend.mdx +82 -0
  101. package/docs/llms-txt.mdx +4 -0
  102. package/docs/openapi.yaml +2944 -0
  103. package/docs/pricing.mdx +22 -0
  104. package/docs/quickstarts/astro.mdx +185 -0
  105. package/docs/quickstarts/cloudflare-workers.mdx +190 -0
  106. package/docs/quickstarts/express.mdx +190 -0
  107. package/docs/quickstarts/fastapi.mdx +282 -0
  108. package/docs/quickstarts/flask.mdx +282 -0
  109. package/docs/quickstarts/hono.mdx +221 -0
  110. package/docs/quickstarts/nextjs-fastapi.mdx +147 -0
  111. package/docs/quickstarts/nextjs-flask.mdx +147 -0
  112. package/docs/quickstarts/nuxt.mdx +169 -0
  113. package/docs/quickstarts/platforms.mdx +78 -0
  114. package/docs/quickstarts/solidjs.mdx +161 -0
  115. package/docs/quickstarts/svelte.mdx +170 -0
  116. package/docs/quickstarts/tanstack-start.mdx +205 -0
  117. package/docs/quickstarts/vercel-nextjs.mdx +233 -0
  118. package/docs/roadmap.mdx +8 -0
  119. package/docs/sdk/workflow-js.mdx +4 -0
  120. package/docs/sdk/workflow-py.mdx +4 -0
  121. package/docs/steps/api.mdx +64 -0
  122. package/docs/steps/call.mdx +183 -0
  123. package/docs/steps/cancel.mdx +25 -0
  124. package/docs/steps/createWebhook.mdx +40 -0
  125. package/docs/steps/invoke.mdx +100 -0
  126. package/docs/steps/notify.mdx +105 -0
  127. package/docs/steps/run.mdx +150 -0
  128. package/docs/steps/sleep.mdx +97 -0
  129. package/docs/steps/sleepUntil.mdx +88 -0
  130. package/docs/steps/waitForEvent.mdx +60 -0
  131. package/docs/steps/waitForWebhook.mdx +78 -0
  132. package/docs/steps.mdx +108 -0
  133. package/docs/troubleshooting/general.mdx +331 -0
  134. package/docs/troubleshooting/vercel.mdx +82 -0
  135. package/express.d.mts +19 -2
  136. package/express.d.ts +19 -2
  137. package/express.js +670 -159
  138. package/express.mjs +1 -1
  139. package/h3.d.mts +19 -2
  140. package/h3.d.ts +19 -2
  141. package/h3.js +670 -159
  142. package/h3.mjs +1 -1
  143. package/hono.d.mts +17 -2
  144. package/hono.d.ts +17 -2
  145. package/hono.js +670 -159
  146. package/hono.mjs +1 -1
  147. package/index.d.mts +50 -21
  148. package/index.d.ts +50 -21
  149. package/index.js +686 -171
  150. package/index.mjs +17 -13
  151. package/nextjs.d.mts +40 -2
  152. package/nextjs.d.ts +40 -2
  153. package/nextjs.js +670 -159
  154. package/nextjs.mjs +1 -1
  155. package/package.json +1 -1
  156. package/react-router.d.mts +16 -2
  157. package/react-router.d.ts +16 -2
  158. package/react-router.js +670 -159
  159. package/react-router.mjs +1 -1
  160. package/{serve-many-CG3BFvO3.d.mts → serve-many-BKukvLNl.d.mts} +1 -1
  161. package/{serve-many-iJF1IUXk.d.ts → serve-many-CrLKQpuZ.d.ts} +1 -1
  162. package/solidjs.d.mts +10 -1
  163. package/solidjs.d.ts +10 -1
  164. package/solidjs.js +670 -159
  165. package/solidjs.mjs +1 -1
  166. package/src/platforms/astro.ts +84 -0
  167. package/src/platforms/cloudflare.ts +127 -0
  168. package/src/platforms/express.ts +147 -0
  169. package/src/platforms/h3.ts +105 -0
  170. package/src/platforms/hono.ts +103 -0
  171. package/src/platforms/nextjs.ts +193 -0
  172. package/src/platforms/react-router.ts +92 -0
  173. package/src/platforms/solidjs.ts +59 -0
  174. package/src/platforms/svelte.ts +99 -0
  175. package/src/platforms/tanstack.ts +96 -0
  176. package/src/src/client/dlq.ts +387 -0
  177. package/src/src/client/filter-types.ts +166 -0
  178. package/src/src/client/index.ts +350 -0
  179. package/src/src/client/types.ts +501 -0
  180. package/src/src/client/utils.ts +307 -0
  181. package/src/src/constants.ts +82 -0
  182. package/src/src/context/api/anthropic.ts +58 -0
  183. package/src/src/context/api/base.ts +52 -0
  184. package/src/src/context/api/index.ts +24 -0
  185. package/src/src/context/api/openai.ts +125 -0
  186. package/src/src/context/api/resend.ts +57 -0
  187. package/src/src/context/auto-executor.ts +707 -0
  188. package/src/src/context/context.ts +681 -0
  189. package/src/src/context/index.ts +1 -0
  190. package/src/src/context/provider.ts +37 -0
  191. package/src/src/context/steps.ts +965 -0
  192. package/src/src/error.ts +203 -0
  193. package/src/src/index.ts +13 -0
  194. package/src/src/middleware/default-callbacks.ts +20 -0
  195. package/src/src/middleware/index.ts +2 -0
  196. package/src/src/middleware/logging.ts +39 -0
  197. package/src/src/middleware/manager.ts +148 -0
  198. package/src/src/middleware/middleware.ts +46 -0
  199. package/src/src/middleware/types.ts +72 -0
  200. package/src/src/qstash/headers.ts +397 -0
  201. package/src/src/qstash/step-config.ts +268 -0
  202. package/src/src/qstash/submit-steps.ts +284 -0
  203. package/src/src/serve/authorization.ts +118 -0
  204. package/src/src/serve/index.ts +475 -0
  205. package/src/src/serve/multi-region/handlers.ts +225 -0
  206. package/src/src/serve/multi-region/utils.ts +88 -0
  207. package/src/src/serve/options.ts +241 -0
  208. package/src/src/serve/serve-many.ts +117 -0
  209. package/src/src/serve/utils.ts +11 -0
  210. package/src/src/types.ts +590 -0
  211. package/src/src/utils.ts +141 -0
  212. package/src/src/workflow-parser.ts +472 -0
  213. package/src/src/workflow-requests.ts +575 -0
  214. package/svelte.d.mts +17 -2
  215. package/svelte.d.ts +17 -2
  216. package/svelte.js +670 -159
  217. package/svelte.mjs +1 -1
  218. package/tanstack.d.mts +15 -2
  219. package/tanstack.d.ts +15 -2
  220. package/tanstack.js +670 -159
  221. package/tanstack.mjs +1 -1
  222. package/{types-CekOpKvz.d.ts → types-CrgK5P6p.d.mts} +372 -32
  223. package/{types-CekOpKvz.d.mts → types-CrgK5P6p.d.ts} +372 -32
@@ -0,0 +1,116 @@
1
+ ---
2
+ title: "Webhooks"
3
+ ---
4
+
5
+ The Webhook feature allows you to pause workflow execution and wait for a webhook URL to be called, enabling seamless integration with third-party APIs and asynchronous operations.
6
+
7
+ This feature is perfect for scenarios where you need to:
8
+ - Wait for external API processing to complete
9
+ - Integrate with services that use callback URLs
10
+ - Receive notifications from external webhooks
11
+
12
+ ## How Webhooks Work
13
+
14
+ When you use webhooks in your workflow, Upstash Workflow:
15
+
16
+ 1. **Creates a unique webhook URL** via `context.createWebhook()`
17
+ 2. **Provides the URL to external services** (typically through `context.call()`)
18
+ 3. **Pauses execution** via `context.waitForWebhook()` until the webhook is called
19
+ 4. **Resumes workflow** when the webhook receives a request or timeout is reached
20
+
21
+ This happens without keeping your serverless function running, making it cost-effective for long-running integrations.
22
+
23
+ ## Examples
24
+
25
+ ### Basic Usage
26
+
27
+ ```typescript
28
+ import { serve } from "@upstash/workflow/nextjs";
29
+
30
+ export const { POST } = serve(async (context) => {
31
+ // Step 1: Create webhook
32
+ const webhook = await context.createWebhook("create webhook");
33
+
34
+ // Step 2: Call an external endpoint, which calls the webhookUrl upon completion
35
+ const callResult = await context.call("call webhook caller", {
36
+ url: "https://webhook/caller",
37
+ method: "POST",
38
+ body: JSON.stringify({
39
+ webhookUrl: webhook.webhookUrl,
40
+ }),
41
+ });
42
+
43
+ // Step 3: Wait for the webhook to be called
44
+ const webhookResponse = await context.waitForWebhook(
45
+ "wait for webhook",
46
+ webhook,
47
+ "30s" // timeout
48
+ );
49
+
50
+ if (webhookResponse.timeout) {
51
+ console.log("Webhook was not called in time");
52
+ // Handle timeout scenario
53
+ } else {
54
+ console.log("Webhook received:", webhookResponse.request);
55
+ // Process the webhook data
56
+ }
57
+ });
58
+ ```
59
+
60
+ ### Waiting for Multiple Calls
61
+
62
+ Some services send multiple progress updates to a webhook URL as processing continues. You can wait for the same webhook multiple times in a loop until you receive a final "finished" signal:
63
+
64
+ ```typescript
65
+ while (true) {
66
+ const webhookResponse = await context.waitForWebhook(
67
+ `wait for progress update ${stepCount}`,
68
+ webhook,
69
+ "5m" // 5 minute timeout between updates
70
+ );
71
+
72
+ if (webhookResponse.timeout) {
73
+ console.log("No progress update received in time, exiting");
74
+ break;
75
+ } else {
76
+ const request = webhookResponse.request;
77
+ console.log("Progress update received:", await request.json());
78
+
79
+ if (request.headers.get("x-task-finished") === "true") {
80
+ console.log("Task finished, exiting loop");
81
+ break;
82
+ }
83
+ }
84
+ }
85
+ ```
86
+
87
+ ## Race Condition Safety
88
+
89
+ Webhooks have built-in **lookback** protection, making them safer against race conditions. If an external service calls the webhook URL before `context.waitForWebhook()` is executed, the webhook call is stored and will be returned when `waitForWebhook` is called.
90
+
91
+ This means you don't need to worry about timing issues between creating the webhook and waiting for it - the workflow will always receive the callback even if it arrives early.
92
+
93
+ ## Comparison with Wait for Event
94
+
95
+ Webhooks and [Wait for Event](/workflow/features/wait-for-event) serve similar purposes but with different approaches:
96
+
97
+ | Feature | Webhooks | Wait for Event |
98
+ |---------|----------|----------------|
99
+ | **Trigger** | External HTTP call to unique URL | Notify via Upstash Workflow Client |
100
+ | **Setup** | Create webhook, pass URL to external service | Share event ID with external service |
101
+ | **Integration** | Easy with callback-based APIs | Requires Workflow Client integration |
102
+ | **Lookback** | ✅ Yes - safe against race conditions | ⚠️ Only when notifying a specific run with `workflowRunId`; otherwise notify before wait is lost |
103
+ | **Best For** | Third-party API callbacks | Internal event notifications |
104
+
105
+ Choose webhooks when integrating with external services that support callback URLs, or when you need protection against race conditions without knowing the target workflow run. Choose Wait for Event when you have control over the notification mechanism and can use the Workflow Client. If you know the workflow run ID, pass it as `workflowRunId` to `notify` to enable [lookback](/workflow/features/wait-for-event#option-1-lookback-with-workflowrunid).
106
+
107
+ ## API Reference
108
+
109
+ <CardGroup cols={2}>
110
+ <Card title="context.createWebhook" icon="webhook" href="/workflow/basics/context/createWebhook">
111
+ Create a unique webhook URL for external services to call
112
+ </Card>
113
+ <Card title="context.waitForWebhook" icon="clock" href="/workflow/basics/context/waitForWebhook">
114
+ Wait for the webhook to be called or timeout
115
+ </Card>
116
+ </CardGroup>
@@ -0,0 +1,200 @@
1
+ ---
2
+ title: Workflow Overview
3
+ sidebarTitle: "Overview"
4
+ ---
5
+
6
+ import { Catalog } from "/snippets/catalog.jsx";
7
+ import { AgentSetup } from "/snippets/agent-setup.jsx";
8
+
9
+ <AgentSetup product="Workflow" />
10
+
11
+ Upstash Workflow lets you write **durable, reliable and performant serverless functions**. Get delivery guarantees, automatic retries on failure, scheduling and more without managing any infrastructure.
12
+
13
+ <iframe
14
+ id="intro-video"
15
+ width="720"
16
+ height="405"
17
+ src="https://www.youtube.com/embed/5As9tZMN3a8?rel=0&disablekb=1"
18
+ title="YouTube video player"
19
+ frameBorder="0"
20
+ allow="accelerometer; fullscreen; clipboard-write; encrypted-media; gyroscope"
21
+ allowFullScreen
22
+ ></iframe>
23
+
24
+
25
+ ## Quickstarts
26
+
27
+ Upstash Workflow supports Next.js, Cloudflare Workers and [many other frameworks](/workflow/quickstarts/platforms) in TypeScript and Python.
28
+
29
+ <CardGroup cols={2}>
30
+ <Card
31
+ title="Next.js"
32
+ icon="node-js"
33
+ href="/workflow/quickstarts/vercel-nextjs"
34
+ >
35
+ Build a Next.js application with QStash Workflow
36
+ </Card>
37
+ <Card
38
+ title="Cloudflare Workers"
39
+ icon="cloudflare"
40
+ href="/workflow/quickstarts/cloudflare-workers"
41
+ >
42
+ Use and deploy Upstash Workflow on Cloudflare Workers
43
+ </Card>
44
+ <Card
45
+ title="Next.js & FastAPI"
46
+ icon="python"
47
+ href="/workflow/quickstarts/nextjs-fastapi"
48
+ >
49
+ Use Upstash Workflow for Python with Next.js and FastAPI
50
+ </Card>
51
+ </CardGroup>
52
+
53
+ ## Key Features
54
+
55
+ <CardGroup cols={2}>
56
+ <Card
57
+ title="Failure Resilience"
58
+ icon="shield"
59
+ >
60
+ If your platform experiences a temporary outage, your workflow can pick up right where it left off, ensuring stability even in unstable environments.
61
+ </Card>
62
+ <Card
63
+ title="Long-Running Executions"
64
+ icon="clock"
65
+ >
66
+ Run long-running REST endpoints, such as complex AI models or video processing tools, even on serverless platforms with strict time limits.
67
+ </Card>
68
+ <Card
69
+ title="Events with Wait/Notify Mechanism"
70
+ icon="bell"
71
+ href="/workflow/features/wait-for-event"
72
+ >
73
+ Create workflows that wait for external events before proceeding. Ideal for user confirmations and asynchronous notifications.
74
+ </Card>
75
+ <Card
76
+ title="Scheduled Jobs"
77
+ icon="calendar"
78
+ href="/workflow/howto/schedule"
79
+ >
80
+ Run jobs at regular intervals with support for cron expressions. Perfect for recurring tasks like reminders, reports, or newsletters.
81
+ </Card>
82
+ <Card
83
+ title="Parallel Runs"
84
+ icon="road"
85
+ href="/workflow/features/parallel-steps"
86
+ >
87
+ Start independent tasks in parallel and wait for them to finish simultaneously, reducing latency.
88
+ </Card>
89
+ <Card
90
+ title="Long Delays"
91
+ icon="hourglass"
92
+ href="/workflow/basics/context/sleep"
93
+ >
94
+ Need your code to “sleep” for days, weeks, or even months? Supports long delays beyond serverless time limits.
95
+ </Card>
96
+ <Card
97
+ title="Delivery Guarantees"
98
+ icon="rotate-right"
99
+ >
100
+ Ensures at-least-once delivery. Failed requests are logged in a Dead Letter Queue to prevent data loss.
101
+ </Card>
102
+ <Card
103
+ title="Flow Control"
104
+ icon="gauge"
105
+ href="/workflow/features/flow-control"
106
+ >
107
+ Prevent overwhelming your app or external services by configuring rate per second or parallelism limits.
108
+ </Card>
109
+ <Card
110
+ title="Observability"
111
+ icon="eye"
112
+ href="/workflow/basics/client/logs"
113
+ >
114
+ Monitor workflow steps with insights. Filter events to track successes, failures, retries, and stalls.
115
+ </Card>
116
+ </CardGroup>
117
+
118
+
119
+ ## Example Use Cases
120
+
121
+ Here are some example real world use-cases for Upstash Workflow:
122
+
123
+ <CardGroup cols={2}>
124
+ <Card title="Agents" icon="robot" href="/workflow/agents/overview">
125
+ Use LLM Agents equipped with custom tools to achieve tasks
126
+ </Card>
127
+ <Card title="AI Data Processing" icon="sparkles" href="/workflow/examples/allInOne">
128
+ Download a large dataset without timeouts, process the data in chunks and generate a report.
129
+ </Card>
130
+ <Card
131
+ title="Waiting For Events"
132
+ icon="traffic-light"
133
+ href="/workflow/examples/waitForEvent"
134
+ >
135
+ Control workflow execution with events, log event data and send emails
136
+ </Card>
137
+ <Card
138
+ title="Authorization Webhook"
139
+ icon="webhook"
140
+ href="/workflow/examples/authWebhook"
141
+ >
142
+ Start a workflow from a webhook. Handle user creation, trial management,
143
+ email reminders and notifications.
144
+ </Card>
145
+ <Card
146
+ title="Customer Onboarding"
147
+ icon="user"
148
+ href="/workflow/examples/customerOnboarding"
149
+ >
150
+ Register a new user, send welcome emails, and periodically check and respond
151
+ to the user's activity state with emails.
152
+ </Card>
153
+ <Card
154
+ title="E-Commerce Order Fulfillment"
155
+ icon="boxes"
156
+ href="/workflow/examples/eCommerceOrderFulfillment"
157
+ >
158
+ Receive an order request, verify the stock, process the payment, and handle
159
+ order dispatch and customer notifications.
160
+ </Card>
161
+ <Card
162
+ title="Image Processing"
163
+ icon="image"
164
+ href="/workflow/examples/imageProcessing"
165
+ >
166
+ Manage uploading images to the data store. Apply filters and resize the
167
+ images to different resolutions in parallel.
168
+ </Card>
169
+ <Card
170
+ title="Retry Payments"
171
+ icon="credit-card"
172
+ href="/workflow/examples/paymentRetry"
173
+ >
174
+ Retry payments with a day of delay, send emails, and suspend account if
175
+ payment fails after the retries.
176
+ </Card>
177
+ </CardGroup>
178
+
179
+ ## How it works
180
+
181
+ Upstash Workflow builds on the principle of steps. Instead of defining a single, complex piece of business logic, workflows contain multiple individual steps.
182
+
183
+ Each of the steps are executed by a separate request to your application, by preserving the output of previous steps.
184
+
185
+ In case of an error, a failed step is retried individually without needing to re-run any previous steps. Instead of the entire business logic, _each step_ can take up your serverless function execution duration, and many more benefits.
186
+
187
+ <Frame>
188
+ <img src="/img/qstash-workflow/workflow-concept.png" alt="Workflow execution diagram" />
189
+ </Frame>
190
+
191
+ ## Support
192
+
193
+ Need help or have questions? We're here to support you:
194
+
195
+ - Join our Discord community to ask questions and share feedback
196
+ - Open a ticket through the Intercom chatbox in the dashboard for any issue
197
+
198
+ ## SDKs
199
+
200
+ <Catalog product="workflow" type="sdk" cols={3} />
@@ -0,0 +1,50 @@
1
+ ---
2
+ title: "Cancel a Run"
3
+ ---
4
+
5
+ You can cancel a running workflow both programatically and from your Upstash Workflow console.
6
+
7
+ ## Cancelling via console
8
+
9
+ In your Upstash Workflow console, find the run you'd like to cancel and press the `Cancel Workflow` button on the right side:
10
+
11
+ <Frame>
12
+ <img src="/img/qstash-workflow/cancel_workflow.png" alt="Cancel a workflow run in the Upstash Console" />
13
+ </Frame>
14
+
15
+ ## Cancelling in bulk
16
+
17
+ To cancel many runs at once, filter the `Logs` tab down to the runs you want
18
+ and pick **Cancel** from the **Bulk actions** menu. QStash cancels every running
19
+ workflow that matches the filters in the background.
20
+
21
+ The **History** button next to the menu lists each bulk cancellation with its
22
+ state, the filters used and the number of runs cancelled, so you can follow an
23
+ operation while it runs or look it up later by its action ID. The same is
24
+ available through the [bulk cancel workflow runs](/workflow/api-reference/runs/bulk-cancel-workflow-runs)
25
+ endpoint with `"async": true`, and the
26
+ [bulk actions](/workflow/api-reference/bulk-actions/list-bulk-actions) endpoints.
27
+
28
+ <Frame caption="The bulk action history panel">
29
+ <img src="/img/qstash/bulk-actions-history.jpg" alt="Bulk action history panel in the Upstash Console" />
30
+ </Frame>
31
+
32
+ ## Cancelling programatically
33
+
34
+ <Note>
35
+ This feature is not yet available in
36
+ [workflow-py](https://github.com/upstash/workflow-py). See our
37
+ [Roadmap](/workflow/roadmap) for feature parity plans and
38
+ [Changelog](/workflow/changelog) for updates.
39
+ </Note>
40
+
41
+ ```javascript
42
+ import { Client } from "@upstash/workflow";
43
+
44
+ const client = new Client({ token: "<QSTASH_TOKEN>" });
45
+ await client.cancel({ ids: "<WORKFLOW_RUN_ID>" });
46
+ ```
47
+
48
+ And replace `<WORKFLOW_RUN_ID>` with your actual run ID. See [the documentation of `client.cancel` method for more information about other ways of canceling workflows](/workflow/basics/client/cancel).
49
+
50
+ You can also use the [Upstash Workflow REST API](/workflow/api-reference/runs/cancel-workflow-run) to cancel a run programatically.
@@ -0,0 +1,33 @@
1
+ ---
2
+ title: "Update a Workflow"
3
+ ---
4
+
5
+ Workflows are composed of multiple steps. When you modify workflow code, it's important to consider how these changes might affect in-progress workflows.
6
+
7
+ ## Issues
8
+
9
+ You cannot change the step order of an existing workflow.
10
+
11
+ If your code changes remove or reorder existing steps, in-progress workflows may attempt to continue from a point that no longer exists. This can lead to workflow failures, typically resulting in the following error:
12
+
13
+ ```bash
14
+ HTTP status 400. Incompatible step name. Expected <STEP_NAME>, got <STEP_NAME>
15
+ ```
16
+
17
+ ## Safe changes
18
+
19
+ Updating workflow code is safe in the following cases:
20
+
21
+ - No active workflow runs exist
22
+ - Only new steps are added to the end of the workflow
23
+
24
+ ## Guidelines for updating workflows
25
+
26
+ Consider the following approaches when updating your workflow code:
27
+
28
+ - **Accept potential failures:** If you're fine with in-progress workflows failing, you can make any code changes.
29
+ - **Use a different route:** To avoid failures, consider serving the updated workflow under a different route.
30
+ - **Stop traffic before deployment:** If you need to keep the same route, stop all traffic before deploying new code.
31
+ - **Add steps only:** If stopping traffic is not an option, limit your changes to adding new steps at the end of the workflow.
32
+
33
+ For a deeper understanding of these limitations, see our [how workflows work](/workflow/basics/how) section.
@@ -0,0 +1,42 @@
1
+ ---
2
+ title: "Configure a Run"
3
+ ---
4
+
5
+ You can configure a workflow run when starting it. The following are the options you can configure:
6
+
7
+ 1. Retries: The number of retry attempt Upstash Workflow does when a step fails in the workflow run
8
+ 2. Retry Delay: The delay strategy between retries when Upstash Workflow attempts retries.
9
+ 3. Flow Control: The rate, period and parallelism that steps should respect and logical grouping key to share with other workflow runs.
10
+
11
+ You can pass these configuration options when starting a workflow run:
12
+
13
+ ```typescript
14
+ import { Client } from "@upstash/workflow";
15
+
16
+ const client = Client()
17
+
18
+ const { workflowRunId } = await client.trigger({
19
+ url: `http://localhost:3000/api/workflow`,
20
+ retries: 3,
21
+ retryDelay: "(1 + retries) * 1000",
22
+ flowControl: {
23
+ key: "limit-ads",
24
+ rate: 1,
25
+ parallelism: 10
26
+ }
27
+ });
28
+ ```
29
+
30
+ The workflow run configuration does **not** apply to `context.call()` and `context.invoke()` steps.
31
+ These steps accept their own configuration options, allowing fine-grained control over external requests.
32
+ If not specified, they fall back to their default values.
33
+
34
+ For details, see:
35
+ - [context.call](/workflow/steps/call)
36
+ - [context.invoke](/workflow/steps/invoke)
37
+
38
+ <Tip>
39
+ A single `context.run` step can override the run's flow control and retry configuration by passing
40
+ `flowControl`, `retries` or `retryDelay` as its third argument. See
41
+ [step-level flow control](/workflow/features/flow-control#step-level-flow-control).
42
+ </Tip>
@@ -0,0 +1,185 @@
1
+ ---
2
+ title: "Handle Failed Runs"
3
+ ---
4
+
5
+ This guide shows you how to **gracefully handle failed workflow runs**. This involves best practices on resolving runtime errors, logging and manually retrying runs that have failed multiple times.
6
+
7
+ ## Why a workflow might fail
8
+
9
+ - A step in your workflow throws a database error that causes your code to fail at runtime.
10
+ - QStash calls your workflow URL, but the URL is not reachable - for example, because of a temporary outage of your deployment platform.
11
+ - A single step takes longer than your platform's function execution limit.
12
+
13
+ Workflow automatically retries a failed step based on your configuration (by default, it retries three times with exponential backoff).
14
+ This helps handle temporary outages or intermittent failures gracefully.
15
+
16
+ <Frame caption="A failed step is automatically retried three times">
17
+ <img src="/img/qstash-workflow/automatic_retry.png" alt="A failed step is automatically retried three times" />
18
+ </Frame>
19
+
20
+ If, even after all retries, your step does not succeed, we'll move the failed run into your [Dead Letter Queue (DLQ)](/qstash/howto/handling-failures#dead-letter-queue). That way, you can always manually retry it again and debug the issue.
21
+
22
+ <Frame caption="Manually retry from the Dead-Letter-Queue (DLQ)">
23
+ <img src="/img/qstash-workflow/workflow_dlq.png" alt="Manually retry from the Dead-Letter-Queue (DLQ)" />
24
+ </Frame>
25
+
26
+ If you want to take an action (a cleanup/log), you can configure either `failureFunction` or a `failureUrl` on the `serve` method of your workflow.
27
+ These options allow you to define custom logic or an external endpoint that will be triggered when a failure occurs.
28
+
29
+ While a step is waiting for its next retry, you can retry it immediately from the console. See [Run a Step Now](/workflow/howto/retry-now).
30
+
31
+ ## Using a `failureFunction` (recommended)
32
+
33
+ The `serve` function you use to create a workflow endpoint accepts a `failureFunction` parameter - an easy way to gracefully handle errors (i.e. logging them to Sentry) or your custom handling logic.
34
+
35
+
36
+ <CodeGroup>
37
+ ```typescript TypeScript
38
+ export const { POST } = serve<string>(
39
+ async (context) => {
40
+ // Your workflow logic...
41
+ },
42
+ {
43
+ failureFunction: async ({
44
+ context,
45
+ failStatus,
46
+ failResponse,
47
+ failHeaders,
48
+ }) => {
49
+ // Handle error, i.e. log to Sentry
50
+ console.error("Workflow failed:", failResponse);
51
+
52
+ // You can optionally return a string that will be visible
53
+ // in the UI (coming soon) and in workflow logs
54
+ return `Workflow failed with status ${failStatus}: ${failResponse}`;
55
+ },
56
+ }
57
+ );
58
+ ```
59
+
60
+ ```python Python
61
+ async def failure_function(
62
+ context, # context during failure
63
+ fail_status, # failure status
64
+ fail_response, # failure message
65
+ fail_headers # failure headers
66
+ ):
67
+ # handle the failure
68
+ pass
69
+
70
+ @serve.post("/api/example", failure_function=failure_function)
71
+ async def example(context: AsyncWorkflowContext[str]) -> None: ...
72
+ ```
73
+
74
+ </CodeGroup>
75
+
76
+ Note: If you use a custom authorization method to secure your workflow endpoint, add authorization to the `failureFunction` too. Otherwise, anyone can invoke your failure function. Read more here: [securing your workflow endpoint](/workflow/howto/security).
77
+
78
+ In `@upstash/workflow`, the `failureFunction` can optionally return a string value that will be displayed in the UI (coming soon) and included in the workflow logs. This is useful for providing custom error messages, debugging information, or tracking specific failure conditions.
79
+
80
+ ## Using a `failureUrl`
81
+
82
+ Instead of using the built-in failure function, you can define a separate failure callback URL.
83
+ Unlike the failure function, which only works when your application is running, the failure URL allows you to handle errors even if your application is completely down.
84
+ If the URL is a different service other than your application, it will be reachable in these cases.
85
+
86
+ By pointing the failure URL to an external service (not hosted within your main application), you ensure that it remains accessible even when your primary app is unavailable.
87
+
88
+ <CodeGroup>
89
+
90
+ ```typescript TypeScript
91
+ export const { POST } = serve<string>(
92
+ async (context) => {
93
+ // Your workflow logic...
94
+ },
95
+ {
96
+ failureUrl: "https://<YOUR_FAILURE_URL>/workflow-failure",
97
+ }
98
+ );
99
+ ```
100
+
101
+ ```python Python
102
+ @serve.post("/api/example", failureUrl="https://<YOUR-FAILURE-ENDPOINT>/...")
103
+ async def example(context: AsyncWorkflowContext[str]) -> None: ...
104
+ ```
105
+
106
+ </CodeGroup>
107
+
108
+ The callback body sent to you will be a JSON object with the following fields:
109
+
110
+ ```javascript JavaScript
111
+ {
112
+ "status": 200,
113
+ "header": { "key": ["value"] }, // Response header
114
+ "body": "YmFzZTY0IGVuY29kZWQgcm9keQ==", // base64 encoded response body
115
+ "retried": 2, // How many times we retried to deliver the original message
116
+ "maxRetries": 3, // Number of retries before the message assumed to be failed to delivered.
117
+ "sourceMessageId": "msg_xxx", // The ID of the message that triggered the callback
118
+ "topicName": "myTopic", // The name of the URL Group (topic) if the request was part of a URL Group
119
+ "endpointName": "myEndpoint", // The endpoint name if the endpoint is given a name within a topic
120
+ "url": "http://myurl.com", // The destination url of the message that triggered the callback
121
+ "method": "GET", // The http method of the message that triggered the callback
122
+ "sourceHeader": { "key": "value" }, // The http header of the message that triggered the callback
123
+ "sourceBody": "YmFzZTY0kZWQgcm9keQ==", // The base64 encoded body of the message that triggered the callback
124
+ "notBefore": "1701198458025", // The unix timestamp of the message that triggered the callback is/will be delivered in milliseconds
125
+ "createdAt": "1701198447054", // The unix timestamp of the message that triggered the callback is created in milliseconds
126
+ "scheduleId": "scd_xxx", // The scheduleId of the message if the message is triggered by a schedule
127
+ "callerIP": "178.247.74.179" // The IP address where the message that triggered the callback is published from
128
+ }
129
+ ```
130
+
131
+ In Next.js you can use the following code to handle the callback:
132
+
133
+ ```javascript JavaScript
134
+ // pages/api/callback.js
135
+
136
+ import { verifySignature } from "@upstash/qstash/nextjs";
137
+
138
+ function handler(req, res) {
139
+ // responses from qstash are base64-encoded
140
+ const decoded = atob(req.body.body);
141
+ console.log(decoded);
142
+
143
+ return res.status(200).end();
144
+ }
145
+
146
+ export default verifySignature(handler);
147
+
148
+ export const config = {
149
+ api: {
150
+ bodyParser: false,
151
+ },
152
+ };
153
+ ```
154
+
155
+ `verifySignature` allows to verify the signature of request, which is signed by Upstash using your signing keys.
156
+ If you don't want to verify the signature, you can remove `QSTASH_CURRENT_SIGNING_KEY` and `QSTASH_NEXT_SIGNING_KEY` environment variables and remove `verifySignature` function.
157
+
158
+
159
+
160
+ ## Manually Handling Failed Workflow Runs
161
+
162
+ When a workflow run fails and is moved to the Dead Letter Queue (DLQ), you have several options to handle it manually via the REST API:
163
+
164
+ ### [Resume](/workflow/api-reference/dlq/resume-workflow-from-dlq)
165
+ - **What it does:** Continues a failed workflow run from exactly where it failed, preserving all successful step results.
166
+ - **When to use:** Use this if you want to retry only the failed/pending steps without re-executing the entire workflow.
167
+
168
+ ### [Restart](/workflow/api-reference/dlq/restart-workflow-from-dlq)
169
+ - **What it does:** Starts the failed workflow run over from the beginning, discarding all previous step results.
170
+ - **When to use:** Use this if you want a clean execution, or if the failure may have been caused by a corrupted state that requires a fresh start.
171
+
172
+ ### [Callback](/workflow/api-reference/dlq/retry-failure-callback)
173
+ - **What it does:** Reruns the failure callback for a workflow run, in case the original failure callback was not delivered or failed.
174
+ - **When to use:** Use this to ensure your system is notified of workflow failures, even if the original callback attempt did not succeed.
175
+
176
+
177
+ ## Debugging failed runs
178
+
179
+ In your DLQ, filter messages via the `Workflow URL` or `Workflow Run ID` to search for a particular failure. We include all request and response headers and bodies to simplify debugging failed runs.
180
+
181
+ For example, let's debug the following failed run. Judging by the status code `404`, the `Ngrok-Error-Code` header of `ERR_NGROK_3200` and the returned HTML body, we know that the URL our workflow called does not exist.
182
+
183
+ <Frame>
184
+ <img src="/img/qstash-workflow/workflow_dlq_debug.png" alt="Debug a failed workflow run in the DLQ" />
185
+ </Frame>
@@ -0,0 +1,18 @@
1
+ ---
2
+ title: "Get your QStash Token"
3
+ ---
4
+
5
+ Upstash Workflow is powered by [QStash](/qstash/overall/getstarted), so your app
6
+ authenticates with a QStash token. Go to the
7
+ [Workflow tab in the Upstash Console](https://console.upstash.com/workflow), pick
8
+ the region you want to use, and copy the `QSTASH_TOKEN` from the **Quickstart**
9
+ section.
10
+
11
+ <Frame>
12
+ <img src="/img/qstash-workflow/console-quickstart-env.jpg" alt="QStash environment variables in the Upstash Console" />
13
+ </Frame>
14
+
15
+ <Info>
16
+ If you want to safely share a token with your team or AI agents, you can use a
17
+ [read-only token](/workflow/howto/readonly-token) instead.
18
+ </Info>