@upstash/workflow 1.4.0-rc → 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.
- package/README.md +9 -0
- package/astro.d.mts +18 -2
- package/astro.d.ts +18 -2
- package/astro.js +129 -29
- package/astro.mjs +1 -1
- package/{chunk-UH6O5IJY.mjs → chunk-J3PXPHSB.mjs} +129 -29
- package/cloudflare.d.mts +16 -2
- package/cloudflare.d.ts +16 -2
- package/cloudflare.js +129 -29
- package/cloudflare.mjs +1 -1
- package/docs/agents/examples.mdx +8 -0
- package/docs/agents/features.mdx +374 -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 +567 -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 +104 -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 +2944 -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 +18 -2
- package/express.d.ts +18 -2
- package/express.js +129 -29
- package/express.mjs +1 -1
- package/h3.d.mts +18 -2
- package/h3.d.ts +18 -2
- package/h3.js +129 -29
- package/h3.mjs +1 -1
- package/hono.d.mts +16 -2
- package/hono.d.ts +16 -2
- package/hono.js +129 -29
- package/hono.mjs +1 -1
- package/index.d.mts +49 -21
- package/index.d.ts +49 -21
- package/index.js +145 -41
- package/index.mjs +17 -13
- package/nextjs.d.mts +39 -2
- package/nextjs.d.ts +39 -2
- package/nextjs.js +129 -29
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/react-router.d.mts +15 -2
- package/react-router.d.ts +15 -2
- package/react-router.js +129 -29
- package/react-router.mjs +1 -1
- package/{serve-many-CbIV7145.d.mts → serve-many-BKukvLNl.d.mts} +1 -1
- package/{serve-many-BCtZg31b.d.ts → serve-many-CrLKQpuZ.d.ts} +1 -1
- package/solidjs.d.mts +9 -1
- package/solidjs.d.ts +9 -1
- package/solidjs.js +129 -29
- 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 +16 -2
- package/svelte.d.ts +16 -2
- package/svelte.js +129 -29
- package/svelte.mjs +1 -1
- package/tanstack.d.mts +14 -2
- package/tanstack.d.ts +14 -2
- package/tanstack.js +129 -29
- package/tanstack.mjs +1 -1
- package/{types-ffLPVG5_.d.ts → types-CrgK5P6p.d.mts} +124 -24
- package/{types-ffLPVG5_.d.mts → types-CrgK5P6p.d.ts} +124 -24
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Advanced Options"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Advanced Options are intended to support edge cases or testing pipelines and are **not required for regular use**.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
<ParamField path="failureFunction" type="string">
|
|
9
|
+
Defines a function that executes if the workflow fails after all retries are exhausted.
|
|
10
|
+
|
|
11
|
+
For details, see [failureFunction](/workflow/features/failure-callback).
|
|
12
|
+
|
|
13
|
+
<CodeGroup>
|
|
14
|
+
```typescript TypeScript
|
|
15
|
+
export const { POST } = serve<string>(
|
|
16
|
+
async (context) => { ... },
|
|
17
|
+
{
|
|
18
|
+
failureFunction: async ({
|
|
19
|
+
context, // context during failure
|
|
20
|
+
failStatus, // failure status
|
|
21
|
+
failResponse, // failure message
|
|
22
|
+
failHeaders, // failure headers
|
|
23
|
+
failStack // failure stack trace (if available)
|
|
24
|
+
}) => {
|
|
25
|
+
// handle the failure
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```python Python
|
|
32
|
+
async def failure_function(
|
|
33
|
+
context, # context during failure
|
|
34
|
+
fail_status, # failure status
|
|
35
|
+
fail_response, # failure message
|
|
36
|
+
fail_headers # failure headers
|
|
37
|
+
):
|
|
38
|
+
# handle the failure
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
@serve.post("/api/example", failure_function=failure_function)
|
|
42
|
+
async def example(context: AsyncWorkflowContext[str]) -> None: ...
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
</CodeGroup>
|
|
46
|
+
</ParamField>
|
|
47
|
+
|
|
48
|
+
<ParamField path="failureUrl" type="string">
|
|
49
|
+
|
|
50
|
+
<Note>
|
|
51
|
+
This parameter is only available in Python SDK. In Javascript SDK, you can pass this value when triggering the workflow.
|
|
52
|
+
</Note>
|
|
53
|
+
|
|
54
|
+
The `failureUrl` option defines an external endpoint that will be called if the workflow fails after all retries are exhausted.
|
|
55
|
+
|
|
56
|
+
This option is an advanced alternative to `failureFunction`.
|
|
57
|
+
For more details, see [Advanced failureUrl Option](/workflow/features/failureFunction/advanced).
|
|
58
|
+
|
|
59
|
+
<CodeGroup>
|
|
60
|
+
|
|
61
|
+
```python Python
|
|
62
|
+
@serve.post("/api/example", failureUrl="https://<YOUR-FAILURE-ENDPOINT>/...")
|
|
63
|
+
async def example(context: AsyncWorkflowContext[str]) -> None: ...
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
</CodeGroup>
|
|
67
|
+
</ParamField>
|
|
68
|
+
|
|
69
|
+
<ParamField path="retries" type="number">
|
|
70
|
+
|
|
71
|
+
<Note>
|
|
72
|
+
This parameter is only available in Python SDK. In Javascript SDK, you can pass this value when triggering the workflow.
|
|
73
|
+
</Note>
|
|
74
|
+
|
|
75
|
+
Defines the number of retry attempts if a workflow step fails.
|
|
76
|
+
The default value is 3.
|
|
77
|
+
|
|
78
|
+
For details, see [retry configuration](/workflow/features/retries#configuration).
|
|
79
|
+
|
|
80
|
+
<CodeGroup>
|
|
81
|
+
|
|
82
|
+
```python Python
|
|
83
|
+
@serve.post("/api/example", retries=3)
|
|
84
|
+
async def example(context: AsyncWorkflowContext[str]) -> None: ...
|
|
85
|
+
```
|
|
86
|
+
</CodeGroup>
|
|
87
|
+
</ParamField>
|
|
88
|
+
|
|
89
|
+
<ParamField path="middlewares" type="WorkflowMiddleware[]">
|
|
90
|
+
An array of middleware instances that intercept workflow lifecycle and debug events.
|
|
91
|
+
|
|
92
|
+
Middlewares allow you to hook into various stages of workflow execution (before/after steps, run start/completion)
|
|
93
|
+
and debug events (errors, warnings, info logs).
|
|
94
|
+
|
|
95
|
+
For details and examples, see [Middlewares](/workflow/howto/middlewares).
|
|
96
|
+
|
|
97
|
+
<CodeGroup>
|
|
98
|
+
|
|
99
|
+
```typescript TypeScript
|
|
100
|
+
import { serve } from "@upstash/workflow/nextjs";
|
|
101
|
+
import { loggingMiddleware } from "@upstash/workflow";
|
|
102
|
+
|
|
103
|
+
export const { POST } = serve<string>(
|
|
104
|
+
async (context) => { ... },
|
|
105
|
+
{
|
|
106
|
+
middlewares: [loggingMiddleware]
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
</CodeGroup>
|
|
112
|
+
</ParamField>
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
<ParamField path="initialPayloadParser" type="bool">
|
|
116
|
+
Enables custom parsing of the initial request payload.
|
|
117
|
+
|
|
118
|
+
Use this option if the incoming payload is not plain JSON or a simple string.
|
|
119
|
+
The parser function lets you transform the raw request into a strongly typed
|
|
120
|
+
object before workflow execution begins.
|
|
121
|
+
|
|
122
|
+
<CodeGroup>
|
|
123
|
+
|
|
124
|
+
```typescript TypeScript
|
|
125
|
+
type InitialPayload = {
|
|
126
|
+
foo: string;
|
|
127
|
+
bar: number;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// 👇 1: provide initial payload type
|
|
131
|
+
export const { POST } = serve<InitialPayload>(
|
|
132
|
+
async (context) => {
|
|
133
|
+
// 👇 3: parsing result is available as requestPayload
|
|
134
|
+
const payload: InitialPayload = context.requestPayload;
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
// 👇 2: custom parsing for initial payload
|
|
138
|
+
initialPayloadParser: (initialPayload) => {
|
|
139
|
+
const payload: InitialPayload = parsePayload(initialPayload);
|
|
140
|
+
return payload;
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```python Python
|
|
147
|
+
@dataclass
|
|
148
|
+
class InitialPayload:
|
|
149
|
+
foo: str
|
|
150
|
+
bar: int
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def initial_payload_parser(initial_payload: str) -> InitialPayload:
|
|
154
|
+
return parse_payload(initial_payload)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@serve.post("/api/example", initial_payload_parser=initial_payload_parser)
|
|
158
|
+
async def example(context: AsyncWorkflowContext[InitialPayload]) -> None:
|
|
159
|
+
payload: InitialPayload = context.request_payload
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
</CodeGroup>
|
|
164
|
+
|
|
165
|
+
</ParamField>
|
|
166
|
+
|
|
167
|
+
<ParamField path="schema" type="z.ZodType">
|
|
168
|
+
Alternative to `initialPayloadParser`, you can pass a `schema` in the TypeScript SDK.
|
|
169
|
+
|
|
170
|
+
The schema is used to validate and parse the initial request payload automatically using [Zod](https://zod.dev/).
|
|
171
|
+
|
|
172
|
+
<CodeGroup>
|
|
173
|
+
|
|
174
|
+
```typescript TypeScript
|
|
175
|
+
|
|
176
|
+
import { z } from "zod";
|
|
177
|
+
|
|
178
|
+
const parameters = z.object({ expression: z.string() });
|
|
179
|
+
|
|
180
|
+
export const { POST } = serve(
|
|
181
|
+
async (context) => {
|
|
182
|
+
// context.requestPayload is typed as `{ expression: string }`
|
|
183
|
+
const payload = context.requestPayload;
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
schema: parameters,
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
</CodeGroup>
|
|
192
|
+
</ParamField>
|
|
193
|
+
|
|
194
|
+
<ParamField path="url" type="string">
|
|
195
|
+
Specifies the full endpoint URL of the workflow, including the route path.
|
|
196
|
+
|
|
197
|
+
By default, Upstash Workflow infers the URL from `request.url` when scheduling the next step.
|
|
198
|
+
However, in some environments, `request.url` may resolve to an internal or unreachable address.
|
|
199
|
+
|
|
200
|
+
Use this option when running behind a proxy, reverse proxy, or local tunnel during development where `request.url` cannot be used directly.
|
|
201
|
+
|
|
202
|
+
<CodeGroup>
|
|
203
|
+
|
|
204
|
+
```typescript TypeScript
|
|
205
|
+
export const { POST } = serve<string>(
|
|
206
|
+
async (context) => { ... },
|
|
207
|
+
{
|
|
208
|
+
url: "https://<YOUR-DEPLOYED-APP>.com/api/workflow"
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
```python Python
|
|
214
|
+
@serve.post("/api/example", url="https://<YOUR-DEPLOYED-APP>.com/api/workflow")
|
|
215
|
+
async def example(context: AsyncWorkflowContext[str]) -> None: ...
|
|
216
|
+
```
|
|
217
|
+
</CodeGroup>
|
|
218
|
+
</ParamField>
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
<ParamField path="baseUrl" type="string">
|
|
222
|
+
|
|
223
|
+
Similar to `url`, but `baseUrl` only overrides the base portion of the inferred URL rather than replacing the entire path.
|
|
224
|
+
This is useful when you want to preserve the route structure while changing only the host or scheme.
|
|
225
|
+
|
|
226
|
+
<Tip>
|
|
227
|
+
If you have multiple workflow endpoints, you can set the `UPSTASH_WORKFLOW_URL` environment variable instead of configuring `baseUrl` on each endpoint.
|
|
228
|
+
The `UPSTASH_WORKFLOW_URL` environment variable corresponds directly to this option and configures it globally.
|
|
229
|
+
</Tip>
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
<CodeGroup>
|
|
233
|
+
|
|
234
|
+
```typescript TypeScript
|
|
235
|
+
export const { POST } = serve<string>(
|
|
236
|
+
async (context) => {
|
|
237
|
+
...
|
|
238
|
+
},
|
|
239
|
+
// options:
|
|
240
|
+
{
|
|
241
|
+
baseUrl: "<LOCAL-TUNNEL-PUBLIC-URL>"
|
|
242
|
+
}
|
|
243
|
+
);
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
```python Python
|
|
247
|
+
@serve.post("/api/example", base_url="<LOCAL-TUNNEL-PUBLIC-URL>")
|
|
248
|
+
async def example(context: AsyncWorkflowContext[str]) -> None: ...
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
</CodeGroup>
|
|
253
|
+
</ParamField>
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
<ParamField path="qstashClient" type="object">
|
|
258
|
+
|
|
259
|
+
Use `qstashClient` if you want to provide your own QStash client instead of letting Workflow use the default from environment variables.
|
|
260
|
+
|
|
261
|
+
This is useful if you're working with multiple QStash projects in the same app.
|
|
262
|
+
|
|
263
|
+
<CodeGroup>
|
|
264
|
+
|
|
265
|
+
```typescript TypeScript
|
|
266
|
+
import { Client } from "@upstash/qstash";
|
|
267
|
+
import { serve } from "@upstash/workflow/nextjs";
|
|
268
|
+
|
|
269
|
+
export const { POST } = serve(
|
|
270
|
+
async (context) => { ... },
|
|
271
|
+
{
|
|
272
|
+
qstashClient: new Client({ token: "<QSTASH_TOKEN>" })
|
|
273
|
+
}
|
|
274
|
+
);
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
```python Python
|
|
278
|
+
from qstash import AsyncQStash
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
@serve.post("/api/example", qstash_client=AsyncQStash(os.environ["QSTASH_TOKEN"]))
|
|
282
|
+
async def example(context: AsyncWorkflowContext[str]) -> None: ...
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
</CodeGroup>
|
|
287
|
+
|
|
288
|
+
</ParamField>
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
<ParamField path="receiver" type="object">
|
|
292
|
+
|
|
293
|
+
The `Receiver` verifies that every request to your endpoint actually comes from QStash, blocking anyone else from triggering your workflow.
|
|
294
|
+
|
|
295
|
+
The `receiver` option allows you to pass a QStash Receiver explicitly.
|
|
296
|
+
|
|
297
|
+
By default, Workflow initializes the Receiver automatically using the environment variables `QSTASH_CURRENT_SIGNING_KEY` and `QSTASH_NEXT_SIGNING_KEY`.
|
|
298
|
+
|
|
299
|
+
This is useful if you're working with multiple QStash projects in the same app.
|
|
300
|
+
|
|
301
|
+
<CodeGroup>
|
|
302
|
+
|
|
303
|
+
```typescript TypeScript
|
|
304
|
+
import { Receiver } from "@upstash/qstash";
|
|
305
|
+
import { serve } from "@upstash/workflow/nextjs";
|
|
306
|
+
|
|
307
|
+
export const { POST } = serve<string>(
|
|
308
|
+
async (context) => { ... },
|
|
309
|
+
{
|
|
310
|
+
receiver: new Receiver({
|
|
311
|
+
currentSigningKey: "<QSTASH_CURRENT_SIGNING_KEY>",
|
|
312
|
+
nextSigningKey: "<QSTASH_NEXT_SIGNING_KEY>",
|
|
313
|
+
})
|
|
314
|
+
}
|
|
315
|
+
);
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
```python Python
|
|
319
|
+
from qstash import Receiver
|
|
320
|
+
|
|
321
|
+
@serve.post(
|
|
322
|
+
"/api/example",
|
|
323
|
+
receiver=Receiver(
|
|
324
|
+
current_signing_key=os.environ["QSTASH_CURRENT_SIGNING_KEY"],
|
|
325
|
+
next_signing_key=os.environ["QSTASH_NEXT_SIGNING_KEY"],
|
|
326
|
+
),
|
|
327
|
+
)
|
|
328
|
+
async def example(context: AsyncWorkflowContext[str]) -> None:
|
|
329
|
+
...
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
</CodeGroup>
|
|
333
|
+
|
|
334
|
+
</ParamField>
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
<ParamField path="env" type="object">
|
|
338
|
+
|
|
339
|
+
By default, Workflow uses `process.env` to read credentials and initialize QStash.
|
|
340
|
+
If you're in an environment where `process.env` isn't available, or you want to inject values manually, you can pass them with `env`.
|
|
341
|
+
|
|
342
|
+
Inside your workflow, these values are also exposed on `context.env`.
|
|
343
|
+
|
|
344
|
+
<CodeGroup>
|
|
345
|
+
|
|
346
|
+
```typescript TypeScript
|
|
347
|
+
import { Receiver } from "@upstash/qstash";
|
|
348
|
+
import { serve } from "@upstash/workflow/nextjs";
|
|
349
|
+
|
|
350
|
+
export const { POST } = serve<string>(
|
|
351
|
+
async (context) => {
|
|
352
|
+
// the env option will be available in the env field of the context:
|
|
353
|
+
const env = context.env;
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
env: {
|
|
357
|
+
QSTASH_URL: "<QSTASH_URL>",
|
|
358
|
+
QSTASH_TOKEN: "<QSTASH_TOKEN>",
|
|
359
|
+
QSTASH_CURRENT_SIGNING_KEY: "<QSTASH_CURRENT_SIGNING_KEY>",
|
|
360
|
+
QSTASH_NEXT_SIGNING_KEY: "<QSTASH_NEXT_SIGNING_KEY>",
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
);
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
```python Python
|
|
367
|
+
@serve.post(
|
|
368
|
+
"/api/example",
|
|
369
|
+
env={
|
|
370
|
+
"QSTASH_CURRENT_SIGNING_KEY": os.environ["QSTASH_CURRENT_SIGNING_KEY"],
|
|
371
|
+
"QSTASH_NEXT_SIGNING_KEY": os.environ["QSTASH_NEXT_SIGNING_KEY"],
|
|
372
|
+
},
|
|
373
|
+
)
|
|
374
|
+
async def example(context: AsyncWorkflowContext[str]) -> None:
|
|
375
|
+
...
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
</CodeGroup>
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
</ParamField>
|
|
382
|
+
|
|
383
|
+
<ParamField path="verbose" type="boolean">
|
|
384
|
+
|
|
385
|
+
Enables verbose mode to print detailed logs of workflow execution to the application's `stdout`.
|
|
386
|
+
|
|
387
|
+
Verbose mode is disabled by default.
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
export const { POST } = serve<string>(
|
|
391
|
+
async (context) => { ... },
|
|
392
|
+
{
|
|
393
|
+
verbose: true
|
|
394
|
+
}
|
|
395
|
+
);
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
</ParamField>
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
<ParamField path="disableTelemetry" type="boolean">
|
|
402
|
+
Disables anonymous telemetry data collection for this workflow endpoint. Since we don't collect telemetry
|
|
403
|
+
in Python SDK, this option is only available in the TypeScript SDK.
|
|
404
|
+
|
|
405
|
+
By default, the Upstash Workflow SDK collects anonymous telemetry data to help improve the service.
|
|
406
|
+
The collected data includes:
|
|
407
|
+
|
|
408
|
+
- SDK version
|
|
409
|
+
- Platform (Vercel, AWS, etc.)
|
|
410
|
+
- Runtime version (Node.js, Python, etc.)
|
|
411
|
+
|
|
412
|
+
Set `disableTelemetry` to `true` to opt out of telemetry for this specific workflow endpoint.
|
|
413
|
+
|
|
414
|
+
<CodeGroup>
|
|
415
|
+
|
|
416
|
+
```typescript TypeScript
|
|
417
|
+
export const { POST } = serve<string>(
|
|
418
|
+
async (context) => { ... },
|
|
419
|
+
{
|
|
420
|
+
disableTelemetry: true
|
|
421
|
+
}
|
|
422
|
+
);
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
```python Python
|
|
426
|
+
@serve.post("/api/example", disable_telemetry=True)
|
|
427
|
+
async def example(context: AsyncWorkflowContext[str]) -> None: ...
|
|
428
|
+
```
|
|
429
|
+
</CodeGroup>
|
|
430
|
+
|
|
431
|
+
<Tip>
|
|
432
|
+
You should also
|
|
433
|
+
set [`disableTelemetry` when triggering workflow runs via `client.trigger()`](/workflow/basics/client/trigger#param-disable-telemetry) to fully disable telemetry
|
|
434
|
+
</Tip>
|
|
435
|
+
</ParamField>
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Workflow Serve Overview
|
|
3
|
+
sidebarTitle: "Overview"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Use the `serve()` function to define an endpoint that runs a workflow.
|
|
7
|
+
It accepts two arguments:
|
|
8
|
+
|
|
9
|
+
1. **Route Function**: an async function that receives the workflow context and defines the workflow steps.
|
|
10
|
+
2. **Options**: configuration options for the workflow.
|
|
11
|
+
|
|
12
|
+
<CodeGroup>
|
|
13
|
+
```typescript TypeScript
|
|
14
|
+
import { serve } from "@upstash/workflow/nextjs";
|
|
15
|
+
|
|
16
|
+
export const { POST } = serve(async (context) => {
|
|
17
|
+
// Route function
|
|
18
|
+
}, {
|
|
19
|
+
// Options
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```python Python
|
|
24
|
+
from fastapi import FastAPI
|
|
25
|
+
from upstash_workflow.fastapi import Serve
|
|
26
|
+
from upstash_workflow import AsyncWorkflowContext
|
|
27
|
+
|
|
28
|
+
app = FastAPI()
|
|
29
|
+
serve = Serve(app)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@serve.post("/api/example")
|
|
33
|
+
async def example(context: AsyncWorkflowContext[str]) -> None:
|
|
34
|
+
async def _step1() -> str:
|
|
35
|
+
# define a piece of business logic as step 1
|
|
36
|
+
return "step 1 result"
|
|
37
|
+
|
|
38
|
+
result = await context.run("step-1", _step1)
|
|
39
|
+
|
|
40
|
+
async def _step2() -> None:
|
|
41
|
+
# define another piece of business logic as step 2
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
await context.run("step-2", _step2)
|
|
45
|
+
```
|
|
46
|
+
</CodeGroup>
|
|
47
|
+
|
|
48
|
+
## Route Function
|
|
49
|
+
|
|
50
|
+
The route function defines the execution logic of the workflow.
|
|
51
|
+
It is an async function that receives a context object, which is automatically created and passed by Upstash Workflow.
|
|
52
|
+
|
|
53
|
+
The context object provides:
|
|
54
|
+
- **Workflow APIs** – functions for defining workflow steps.
|
|
55
|
+
- **Workflow Run Properties** – request payload, request headers, and other metadata.
|
|
56
|
+
|
|
57
|
+
For a full list of available APIs and properties, see the [Workflow Context](/workflow/basics/context) documentation.
|
|
58
|
+
|
|
59
|
+
<CodeGroup>
|
|
60
|
+
```typescript TypeScript highlight={4-9}
|
|
61
|
+
import { serve } from "@upstash/workflow/nextjs";
|
|
62
|
+
|
|
63
|
+
export const { POST } = serve(
|
|
64
|
+
async (context) => {
|
|
65
|
+
// 👇 Access context properties
|
|
66
|
+
const { userId } = context.requestPayload;
|
|
67
|
+
// 👇 Define a workflow step
|
|
68
|
+
await context.run("step-1", async () => {})
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```python Python
|
|
74
|
+
from fastapi import FastAPI
|
|
75
|
+
from upstash_workflow.fastapi import Serve
|
|
76
|
+
from upstash_workflow import AsyncWorkflowContext
|
|
77
|
+
|
|
78
|
+
app = FastAPI()
|
|
79
|
+
serve = Serve(app)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@serve.post("/api/example")
|
|
83
|
+
async def example(context: AsyncWorkflowContext[str]) -> None:
|
|
84
|
+
async def _step1() -> str:
|
|
85
|
+
# define a piece of business logic as step 1
|
|
86
|
+
return "step 1 result"
|
|
87
|
+
|
|
88
|
+
result = await context.run("step-1", _step1)
|
|
89
|
+
|
|
90
|
+
async def _step2() -> None:
|
|
91
|
+
# define another piece of business logic as step 2
|
|
92
|
+
pass
|
|
93
|
+
|
|
94
|
+
await context.run("step-2", _step2)
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
</CodeGroup>
|
|
98
|
+
|
|
99
|
+
## Options
|
|
100
|
+
|
|
101
|
+
Options provide additional configuration for workflow runs.
|
|
102
|
+
Most of them are advanced settings and are not required for typical use cases. See [Advanced Options](/workflow/basics/serve/advanced) for more details.
|
|
103
|
+
|
|
104
|
+
<CodeGroup>
|
|
105
|
+
|
|
106
|
+
```typescript TypeScript highlight={5-8}
|
|
107
|
+
import { serve } from "@upstash/workflow/nextjs";
|
|
108
|
+
|
|
109
|
+
export const { POST } = serve(
|
|
110
|
+
async (context) => { ... },
|
|
111
|
+
// 👇 Workflow options
|
|
112
|
+
{
|
|
113
|
+
failureFunction: async ({ ... }) => {}
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```python Python
|
|
119
|
+
from fastapi import FastAPI
|
|
120
|
+
from upstash_workflow.fastapi import Serve
|
|
121
|
+
from upstash_workflow import AsyncWorkflowContext
|
|
122
|
+
|
|
123
|
+
app = FastAPI()
|
|
124
|
+
serve = Serve(app)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@serve.post("/api/example")
|
|
128
|
+
async def example(context: AsyncWorkflowContext[str]) -> None:
|
|
129
|
+
async def _step1() -> str:
|
|
130
|
+
# define a piece of business logic as step 1
|
|
131
|
+
return "step 1 result"
|
|
132
|
+
|
|
133
|
+
result = await context.run("step-1", _step1)
|
|
134
|
+
|
|
135
|
+
async def _step2() -> None:
|
|
136
|
+
# define another piece of business logic as step 2
|
|
137
|
+
pass
|
|
138
|
+
|
|
139
|
+
await context.run("step-2", _step2)
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
</CodeGroup>
|