@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,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Return Results from context.run"
|
|
3
|
+
sidebarTitle: "Return Step Results"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Always return step results if needed in subsequent steps.
|
|
7
|
+
|
|
8
|
+
<CodeGroup>
|
|
9
|
+
|
|
10
|
+
```typescript ❌ Incorrect - TypeScript
|
|
11
|
+
export const { POST } = serve<string>(async (context) => {
|
|
12
|
+
const input = context.requestPayload
|
|
13
|
+
|
|
14
|
+
let result
|
|
15
|
+
|
|
16
|
+
await context.run("step-1", async () => {
|
|
17
|
+
result = await someWork(input)
|
|
18
|
+
})
|
|
19
|
+
await context.run("step-2", async () => {
|
|
20
|
+
await someOtherWork(result)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```typescript ✅ Correct - TypeScript
|
|
26
|
+
export const { POST } = serve<string>(async (context) => {
|
|
27
|
+
const input = context.requestPayload
|
|
28
|
+
|
|
29
|
+
const result = await context.run("step-1", async () => {
|
|
30
|
+
return await someWork(input)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
await context.run("step-2", async () => {
|
|
34
|
+
someOtherWork(result)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```python ❌ Incorrect - Python
|
|
40
|
+
@serve.post("/api/example")
|
|
41
|
+
async def example(context: AsyncWorkflowContext[str]) -> None:
|
|
42
|
+
input = context.request_payload
|
|
43
|
+
|
|
44
|
+
result = None
|
|
45
|
+
|
|
46
|
+
async def _step_1() -> Dict:
|
|
47
|
+
nonlocal result
|
|
48
|
+
result = await some_work(input)
|
|
49
|
+
|
|
50
|
+
await context.run("step-1", _step_1)
|
|
51
|
+
|
|
52
|
+
async def _step_2() -> None:
|
|
53
|
+
await some_other_work(result)
|
|
54
|
+
|
|
55
|
+
await context.run("step-2", _step_2)
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```python ✅ Correct - Python
|
|
60
|
+
@serve.post("/api/example")
|
|
61
|
+
async def example(context: AsyncWorkflowContext[str]) -> None:
|
|
62
|
+
input = context.request_payload
|
|
63
|
+
|
|
64
|
+
async def _step_1() -> Dict:
|
|
65
|
+
return await some_work(input)
|
|
66
|
+
|
|
67
|
+
result = await context.run("step-1", _step_1)
|
|
68
|
+
|
|
69
|
+
async def _step_2() -> None:
|
|
70
|
+
await some_other_work(result)
|
|
71
|
+
|
|
72
|
+
await context.run("step-2", _step_2)
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
</CodeGroup>
|
|
77
|
+
|
|
78
|
+
Because your workflow endpoint is called multiple times, `result` will be uninitialized when the endpoint is called again to run `step-2`.
|
|
79
|
+
|
|
80
|
+
If you are curious about why an endpoint is called multiple times, see [how Workflow works](/workflow/basics/how).
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Avoid Context and Step Limits"
|
|
3
|
+
sidebarTitle: "Workflow Limits"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
A single workflow run has the following hard limits:
|
|
7
|
+
|
|
8
|
+
- **Maximum step count:** 1,000 steps
|
|
9
|
+
- **Maximum context size:** 100 MB
|
|
10
|
+
|
|
11
|
+
These limits are hard limits and do not vary by plan. Avoid putting all of your application logic into one large workflow that could reach either limit.
|
|
12
|
+
|
|
13
|
+
The context size is the combined size of the workflow input and the results of all completed steps. Each new step result is added to that context, so the context grows as the workflow completes more steps. Workflows with many steps, large step results, or both can reach the context size limit.
|
|
14
|
+
|
|
15
|
+
Instead, separate the logic into multiple workflows and connect them with [`context.invoke`](/workflow/features/invoke). Each invoked workflow has its own context containing its input and step results. When the invoked workflow finishes, only its final output is transferred to the parent workflow as the result of a single `context.invoke` step. Its intermediate step results are not added to the parent's context.
|
|
16
|
+
|
|
17
|
+
```typescript app/workflows/[...path]/route.ts
|
|
18
|
+
import type { WorkflowContext } from "@upstash/workflow"
|
|
19
|
+
import { createWorkflow, serveMany } from "@upstash/workflow/nextjs"
|
|
20
|
+
|
|
21
|
+
type BatchInput = { itemIds: string[] }
|
|
22
|
+
|
|
23
|
+
const processBatch = createWorkflow(
|
|
24
|
+
async (context: WorkflowContext<BatchInput>) => {
|
|
25
|
+
const validatedItems = await context.run("validate items", () => {
|
|
26
|
+
return context.requestPayload.itemIds.filter((itemId) => itemId.length > 0)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const processedItems = await context.run("process items", () => {
|
|
30
|
+
return validatedItems.map((itemId) => ({ itemId, processed: true }))
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// Only this final output is transferred to the parent workflow.
|
|
34
|
+
return { processedCount: processedItems.length }
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
const parentWorkflow = createWorkflow(
|
|
39
|
+
async (context: WorkflowContext<BatchInput>) => {
|
|
40
|
+
const { body, isFailed, isCanceled } = await context.invoke(
|
|
41
|
+
"process batch",
|
|
42
|
+
{
|
|
43
|
+
workflow: processBatch,
|
|
44
|
+
body: context.requestPayload,
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if (isFailed || isCanceled) {
|
|
49
|
+
throw new Error("The batch workflow did not complete successfully")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return body
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
export const { POST } = serveMany({
|
|
57
|
+
parent: parentWorkflow,
|
|
58
|
+
"process-batch": processBatch,
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
In this example, `validatedItems` and `processedItems` are stored only in the invoked workflow's context. The parent context receives `{ processedCount }` as one step result. This keeps each workflow focused and prevents intermediate results from accumulating in a single context.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "client.cancel"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Cancel one or more workflow runs. You can pass IDs directly, use filters, or cancel all at once.
|
|
6
|
+
|
|
7
|
+
## Arguments
|
|
8
|
+
|
|
9
|
+
The `cancel` method accepts one of the following:
|
|
10
|
+
|
|
11
|
+
### By ID
|
|
12
|
+
|
|
13
|
+
Pass a single workflow run ID or an array of IDs directly:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
await client.cancel("<WORKFLOW_RUN_ID>");
|
|
17
|
+
await client.cancel(["<ID_1>", "<ID_2>"]);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### By filters
|
|
21
|
+
|
|
22
|
+
Pass an object with a `filter` field containing one or more filter criteria:
|
|
23
|
+
|
|
24
|
+
<ParamField body="filter" type="object">
|
|
25
|
+
<Expandable defaultOpen>
|
|
26
|
+
<ParamField body="workflowUrl" type="string" optional>
|
|
27
|
+
Cancel workflows matching this exact URL. Cannot be combined with `workflowUrlStartingWith`.
|
|
28
|
+
</ParamField>
|
|
29
|
+
|
|
30
|
+
<ParamField body="workflowUrlStartingWith" type="string" optional>
|
|
31
|
+
Cancel workflows whose URL starts with this prefix. Cannot be combined with `workflowUrl`.
|
|
32
|
+
</ParamField>
|
|
33
|
+
|
|
34
|
+
<ParamField body="label" type="string | string[]" optional>
|
|
35
|
+
Cancel workflows with this label. Pass an array to match runs that
|
|
36
|
+
have any of the given labels (OR semantics).
|
|
37
|
+
</ParamField>
|
|
38
|
+
|
|
39
|
+
<ParamField body="fromDate" type="Date | number" optional>
|
|
40
|
+
Cancel workflows created after this date. Accepts `Date` objects or Unix timestamps (ms).
|
|
41
|
+
</ParamField>
|
|
42
|
+
|
|
43
|
+
<ParamField body="toDate" type="Date | number" optional>
|
|
44
|
+
Cancel workflows created before this date. Accepts `Date` objects or Unix timestamps (ms).
|
|
45
|
+
</ParamField>
|
|
46
|
+
|
|
47
|
+
<ParamField body="callerIp" type="string" optional>
|
|
48
|
+
Cancel workflows triggered by this IP address.
|
|
49
|
+
</ParamField>
|
|
50
|
+
|
|
51
|
+
<ParamField body="flowControlKey" type="string" optional>
|
|
52
|
+
Cancel workflows with this flow control key.
|
|
53
|
+
</ParamField>
|
|
54
|
+
</Expandable>
|
|
55
|
+
</ParamField>
|
|
56
|
+
|
|
57
|
+
<ParamField body="count" type="number" optional>
|
|
58
|
+
Maximum number of workflow runs to cancel per call. Defaults to `100`.
|
|
59
|
+
</ParamField>
|
|
60
|
+
|
|
61
|
+
### Cancel all
|
|
62
|
+
|
|
63
|
+
<ParamField body="all" type="boolean">
|
|
64
|
+
Set to `true` to cancel all pending and active workflow runs.
|
|
65
|
+
</ParamField>
|
|
66
|
+
|
|
67
|
+
## Response
|
|
68
|
+
|
|
69
|
+
<ResponseField name="cancelled" type="number">
|
|
70
|
+
The number of workflow runs that were cancelled.
|
|
71
|
+
</ResponseField>
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
### Cancel by ID
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
// cancel a single workflow
|
|
79
|
+
await client.cancel("<WORKFLOW_RUN_ID>");
|
|
80
|
+
|
|
81
|
+
// cancel a set of workflow runs
|
|
82
|
+
await client.cancel(["<WORKFLOW_RUN_ID_1>", "<WORKFLOW_RUN_ID_2>"]);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Cancel with URL filter
|
|
86
|
+
|
|
87
|
+
Cancel all workflow runs on a specific endpoint using a URL prefix:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
await client.cancel({
|
|
91
|
+
filter: { workflowUrlStartingWith: "https://your-endpoint.com" }
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
For an exact URL match:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
await client.cancel({
|
|
99
|
+
filter: { workflowUrl: "https://your-endpoint.com/api/workflow" }
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Cancel with filters
|
|
104
|
+
|
|
105
|
+
You can combine multiple filter parameters:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
// cancel by label
|
|
109
|
+
await client.cancel({ filter: { label: "my-label" } });
|
|
110
|
+
|
|
111
|
+
// cancel by label and date range
|
|
112
|
+
await client.cancel({
|
|
113
|
+
filter: {
|
|
114
|
+
label: "my-label",
|
|
115
|
+
fromDate: 1640995200000,
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// cancel by URL and date range
|
|
120
|
+
await client.cancel({
|
|
121
|
+
filter: {
|
|
122
|
+
workflowUrl: "https://your-endpoint.com/api/workflow",
|
|
123
|
+
fromDate: new Date("2024-01-01"),
|
|
124
|
+
toDate: new Date("2024-06-01"),
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Cancel _all_ workflows
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
let cancelled: number;
|
|
133
|
+
do {
|
|
134
|
+
const result = await client.cancel({ all: true });
|
|
135
|
+
cancelled = result.cancelled;
|
|
136
|
+
} while (cancelled > 0);
|
|
137
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "client.dlq.retryFailureFunction"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
If a workflow's `failureFunction` or `failureUrl` request has failed, you can retry it using the `retryFailureFunction` method:
|
|
6
|
+
|
|
7
|
+
## Arguments
|
|
8
|
+
|
|
9
|
+
## Response
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
```ts
|
|
13
|
+
import { Client } from "@upstash/workflow";
|
|
14
|
+
|
|
15
|
+
const client = new Client({ token: "<QSTASH_TOKEN>" });
|
|
16
|
+
|
|
17
|
+
// Retry the failure callback for a specific DLQ message
|
|
18
|
+
const response = await client.dlq.retryFailureFunction({
|
|
19
|
+
dlqId: "dlq-12345" // The ID of the DLQ message to retry
|
|
20
|
+
});
|
|
21
|
+
```
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "client.dlq.delete"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
The `dlq.delete` method deletes one or more workflow runs from the **Dead Letter Queue (DLQ)**.
|
|
6
|
+
|
|
7
|
+
## Arguments
|
|
8
|
+
|
|
9
|
+
You can delete DLQ entries by ID, by an array of IDs, or by filters.
|
|
10
|
+
|
|
11
|
+
### By DLQ ID
|
|
12
|
+
|
|
13
|
+
Pass a single DLQ ID or an array of IDs directly:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
await client.dlq.delete("dlq-123");
|
|
17
|
+
await client.dlq.delete(["dlq-123", "dlq-456"]);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or as an object with `dlqIds`:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
await client.dlq.delete({ dlqIds: ["dlq-123", "dlq-456"] });
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### By filters
|
|
27
|
+
|
|
28
|
+
<ParamField body="filter" type="object">
|
|
29
|
+
<Expandable defaultOpen>
|
|
30
|
+
<ParamField body="workflowUrl" type="string" optional>
|
|
31
|
+
Filter by exact workflow URL.
|
|
32
|
+
</ParamField>
|
|
33
|
+
|
|
34
|
+
<ParamField body="workflowRunId" type="string" optional>
|
|
35
|
+
Filter by workflow run ID.
|
|
36
|
+
</ParamField>
|
|
37
|
+
|
|
38
|
+
<ParamField body="label" type="string | string[]" optional>
|
|
39
|
+
Delete workflows with this label. Pass an array to match runs that
|
|
40
|
+
have any of the given labels (OR semantics).
|
|
41
|
+
</ParamField>
|
|
42
|
+
|
|
43
|
+
<ParamField body="fromDate" type="Date | number" optional>
|
|
44
|
+
Delete workflows created after this date. Accepts `Date` objects or Unix timestamps (ms).
|
|
45
|
+
</ParamField>
|
|
46
|
+
|
|
47
|
+
<ParamField body="toDate" type="Date | number" optional>
|
|
48
|
+
Delete workflows created before this date. Accepts `Date` objects or Unix timestamps (ms).
|
|
49
|
+
</ParamField>
|
|
50
|
+
|
|
51
|
+
<ParamField body="callerIp" type="string" optional>
|
|
52
|
+
Filter by the IP address that triggered the workflow.
|
|
53
|
+
</ParamField>
|
|
54
|
+
|
|
55
|
+
<ParamField body="flowControlKey" type="string" optional>
|
|
56
|
+
Filter by flow control key.
|
|
57
|
+
</ParamField>
|
|
58
|
+
|
|
59
|
+
<ParamField body="workflowCreatedAt" type="number" optional>
|
|
60
|
+
Filter by workflow creation time (Unix timestamp in ms).
|
|
61
|
+
</ParamField>
|
|
62
|
+
|
|
63
|
+
<ParamField body="failureFunctionState" type="string" optional>
|
|
64
|
+
Filter by failure callback state.
|
|
65
|
+
</ParamField>
|
|
66
|
+
</Expandable>
|
|
67
|
+
</ParamField>
|
|
68
|
+
|
|
69
|
+
<ParamField body="count" type="number" optional>
|
|
70
|
+
Maximum number of messages to process per call. Defaults to `100`.
|
|
71
|
+
</ParamField>
|
|
72
|
+
|
|
73
|
+
<ParamField body="cursor" type="string" optional>
|
|
74
|
+
A pagination cursor from a previous request.
|
|
75
|
+
</ParamField>
|
|
76
|
+
|
|
77
|
+
### Delete all
|
|
78
|
+
|
|
79
|
+
<ParamField body="all" type="boolean">
|
|
80
|
+
Set to `true` to delete all DLQ entries.
|
|
81
|
+
</ParamField>
|
|
82
|
+
|
|
83
|
+
## Response
|
|
84
|
+
|
|
85
|
+
<ResponseField name="deleted" type="number">
|
|
86
|
+
The number of DLQ entries that were deleted.
|
|
87
|
+
</ResponseField>
|
|
88
|
+
|
|
89
|
+
<ResponseField name="cursor" type="string">
|
|
90
|
+
A pagination cursor. If not returned, all matching entries have been processed.
|
|
91
|
+
</ResponseField>
|
|
92
|
+
|
|
93
|
+
## Usage
|
|
94
|
+
|
|
95
|
+
<CodeGroup>
|
|
96
|
+
```ts Single
|
|
97
|
+
await client.dlq.delete("dlq-123");
|
|
98
|
+
```
|
|
99
|
+
```ts Multiple
|
|
100
|
+
await client.dlq.delete(["dlq-123", "dlq-456"]);
|
|
101
|
+
```
|
|
102
|
+
```ts By filters
|
|
103
|
+
// delete by label
|
|
104
|
+
let cursor: string | undefined;
|
|
105
|
+
do {
|
|
106
|
+
const result = await client.dlq.delete({
|
|
107
|
+
filter: { label: "my-label" },
|
|
108
|
+
cursor,
|
|
109
|
+
});
|
|
110
|
+
cursor = result.cursor;
|
|
111
|
+
} while (cursor);
|
|
112
|
+
```
|
|
113
|
+
```ts All
|
|
114
|
+
let cursor: string | undefined;
|
|
115
|
+
do {
|
|
116
|
+
const result = await client.dlq.delete({ all: true, cursor });
|
|
117
|
+
cursor = result.cursor;
|
|
118
|
+
} while (cursor);
|
|
119
|
+
```
|
|
120
|
+
</CodeGroup>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "client.dlq.list"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
The `dlq.list` method retrieves messages that were sent to the **Dead Letter Queue (DLQ)**.
|
|
6
|
+
|
|
7
|
+
DLQ messages represent failed workflow or QStash deliveries that could not be retried successfully.
|
|
8
|
+
|
|
9
|
+
## Arguments
|
|
10
|
+
|
|
11
|
+
<ParamField body="cursor" type="string" optional>
|
|
12
|
+
A pagination cursor from a previous request.
|
|
13
|
+
Use this to fetch the next batch of results.
|
|
14
|
+
</ParamField>
|
|
15
|
+
|
|
16
|
+
<ParamField body="count" type="number" optional>
|
|
17
|
+
Maximum number of DLQ messages to return.
|
|
18
|
+
Defaults to a system-defined limit if not provided.
|
|
19
|
+
</ParamField>
|
|
20
|
+
|
|
21
|
+
<ParamField body="filter" type="object" optional>
|
|
22
|
+
Filter options for narrowing down DLQ messages.
|
|
23
|
+
|
|
24
|
+
<Expandable defaultOpen>
|
|
25
|
+
<ParamField body="workflowUrl" type="string" optional>
|
|
26
|
+
Filter by exact workflow URL.
|
|
27
|
+
</ParamField>
|
|
28
|
+
|
|
29
|
+
<ParamField body="workflowRunId" type="string" optional>
|
|
30
|
+
Filter by workflow run ID.
|
|
31
|
+
</ParamField>
|
|
32
|
+
|
|
33
|
+
<ParamField body="label" type="string | string[]" optional>
|
|
34
|
+
Filter by workflow label. Pass an array to match runs that have any
|
|
35
|
+
of the given labels (OR semantics).
|
|
36
|
+
</ParamField>
|
|
37
|
+
|
|
38
|
+
<ParamField body="fromDate" type="Date | number" optional>
|
|
39
|
+
Earliest date to include. Accepts `Date` objects or Unix timestamps (ms).
|
|
40
|
+
</ParamField>
|
|
41
|
+
|
|
42
|
+
<ParamField body="toDate" type="Date | number" optional>
|
|
43
|
+
Latest date to include. Accepts `Date` objects or Unix timestamps (ms).
|
|
44
|
+
</ParamField>
|
|
45
|
+
|
|
46
|
+
<ParamField body="callerIp" type="string" optional>
|
|
47
|
+
Filter by the IP address that triggered the workflow.
|
|
48
|
+
</ParamField>
|
|
49
|
+
|
|
50
|
+
<ParamField body="flowControlKey" type="string" optional>
|
|
51
|
+
Filter by flow control key.
|
|
52
|
+
</ParamField>
|
|
53
|
+
|
|
54
|
+
<ParamField body="workflowCreatedAt" type="number" optional>
|
|
55
|
+
Filter by workflow creation time (Unix timestamp in ms).
|
|
56
|
+
</ParamField>
|
|
57
|
+
|
|
58
|
+
<ParamField body="failureFunctionState" type="string" optional>
|
|
59
|
+
Filter by failure callback state.
|
|
60
|
+
</ParamField>
|
|
61
|
+
</Expandable>
|
|
62
|
+
</ParamField>
|
|
63
|
+
|
|
64
|
+
## Response
|
|
65
|
+
|
|
66
|
+
<ResponseField name="messages" type="DLQMessage[]">
|
|
67
|
+
An array of DLQ messages that match the provided filters.
|
|
68
|
+
</ResponseField>
|
|
69
|
+
|
|
70
|
+
<ResponseField name="cursor" type="string">
|
|
71
|
+
A cursor to paginate through additional results.
|
|
72
|
+
If not returned, you have reached the end of the DLQ.
|
|
73
|
+
</ResponseField>
|
|
74
|
+
|
|
75
|
+
## Usage
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { Client } from "@upstash/workflow";
|
|
79
|
+
|
|
80
|
+
const client = new Client({ token: "<QSTASH_TOKEN>" });
|
|
81
|
+
|
|
82
|
+
// List all DLQ messages
|
|
83
|
+
const { messages, cursor } = await client.dlq.list();
|
|
84
|
+
|
|
85
|
+
// List with pagination and filtering
|
|
86
|
+
const result = await client.dlq.list({
|
|
87
|
+
cursor,
|
|
88
|
+
count: 10,
|
|
89
|
+
filter: {
|
|
90
|
+
fromDate: Date.now() - 86400000, // last 24 hours
|
|
91
|
+
toDate: Date.now(),
|
|
92
|
+
workflowUrl: "https://your-endpoint.com",
|
|
93
|
+
label: "my-workflow",
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
```
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "client.dlq.restart"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
The `dlq.restart` method restarts one or more workflow runs from **Dead Letter Queue (DLQ)**.
|
|
6
|
+
This allows you to reprocess workflow runs that previously failed after exhausting retries.
|
|
7
|
+
|
|
8
|
+
## Arguments
|
|
9
|
+
|
|
10
|
+
The first argument specifies which DLQ entries to restart. The optional second argument provides flow control and retry settings.
|
|
11
|
+
|
|
12
|
+
### By DLQ ID
|
|
13
|
+
|
|
14
|
+
Pass a single DLQ ID or an array of IDs directly:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
await client.dlq.restart("dlq-12345");
|
|
18
|
+
await client.dlq.restart(["dlq-12345", "dlq-67890"]);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### By filters
|
|
22
|
+
|
|
23
|
+
Pass an object with a `filter` field:
|
|
24
|
+
|
|
25
|
+
<ParamField body="filter" type="object">
|
|
26
|
+
<Expandable defaultOpen>
|
|
27
|
+
<ParamField body="workflowUrl" type="string" optional>
|
|
28
|
+
Filter by exact workflow URL.
|
|
29
|
+
</ParamField>
|
|
30
|
+
|
|
31
|
+
<ParamField body="workflowRunId" type="string" optional>
|
|
32
|
+
Filter by workflow run ID.
|
|
33
|
+
</ParamField>
|
|
34
|
+
|
|
35
|
+
<ParamField body="label" type="string | string[]" optional>
|
|
36
|
+
Restart workflows with this label. Pass an array to match runs that
|
|
37
|
+
have any of the given labels (OR semantics).
|
|
38
|
+
</ParamField>
|
|
39
|
+
|
|
40
|
+
<ParamField body="fromDate" type="Date | number" optional>
|
|
41
|
+
Restart workflows created after this date.
|
|
42
|
+
</ParamField>
|
|
43
|
+
|
|
44
|
+
<ParamField body="toDate" type="Date | number" optional>
|
|
45
|
+
Restart workflows created before this date.
|
|
46
|
+
</ParamField>
|
|
47
|
+
|
|
48
|
+
<ParamField body="callerIp" type="string" optional>
|
|
49
|
+
Filter by the IP address that triggered the workflow.
|
|
50
|
+
</ParamField>
|
|
51
|
+
|
|
52
|
+
<ParamField body="flowControlKey" type="string" optional>
|
|
53
|
+
Filter by flow control key.
|
|
54
|
+
</ParamField>
|
|
55
|
+
|
|
56
|
+
<ParamField body="workflowCreatedAt" type="number" optional>
|
|
57
|
+
Filter by workflow creation time (Unix timestamp in ms).
|
|
58
|
+
</ParamField>
|
|
59
|
+
|
|
60
|
+
<ParamField body="failureFunctionState" type="string" optional>
|
|
61
|
+
Filter by failure callback state.
|
|
62
|
+
</ParamField>
|
|
63
|
+
</Expandable>
|
|
64
|
+
</ParamField>
|
|
65
|
+
|
|
66
|
+
<ParamField body="count" type="number" optional>
|
|
67
|
+
Maximum number of messages to process per call. Defaults to `100`.
|
|
68
|
+
</ParamField>
|
|
69
|
+
|
|
70
|
+
<ParamField body="cursor" type="string" optional>
|
|
71
|
+
A pagination cursor from a previous request.
|
|
72
|
+
</ParamField>
|
|
73
|
+
|
|
74
|
+
### Restart all
|
|
75
|
+
|
|
76
|
+
<ParamField body="all" type="boolean">
|
|
77
|
+
Set to `true` to restart all DLQ entries.
|
|
78
|
+
</ParamField>
|
|
79
|
+
|
|
80
|
+
### Options (second argument)
|
|
81
|
+
|
|
82
|
+
<ParamField body="flowControl" type="object" optional>
|
|
83
|
+
An optional flow control configuration to limit concurrency and execution rate of restarted workflow runs.
|
|
84
|
+
|
|
85
|
+
See [Flow Control](/workflow/features/flow-control) for details.
|
|
86
|
+
|
|
87
|
+
<Expandable title="properties">
|
|
88
|
+
<ParamField body="key" type="string">
|
|
89
|
+
A logical grouping key that identifies which requests share the same flow control limits.
|
|
90
|
+
</ParamField>
|
|
91
|
+
|
|
92
|
+
<ParamField body="rate" type="number">
|
|
93
|
+
The maximum number of allowed requests per second.
|
|
94
|
+
</ParamField>
|
|
95
|
+
|
|
96
|
+
<ParamField body="parallelism" type="number">
|
|
97
|
+
The maximum number of concurrent requests allowed.
|
|
98
|
+
</ParamField>
|
|
99
|
+
|
|
100
|
+
<ParamField body="period" type="string|number">
|
|
101
|
+
The time window used to enforce the defined rate limit. Default is `1s`.
|
|
102
|
+
</ParamField>
|
|
103
|
+
</Expandable>
|
|
104
|
+
|
|
105
|
+
</ParamField>
|
|
106
|
+
|
|
107
|
+
<ParamField body="retries" type="number" optional>
|
|
108
|
+
Number of retry attempts to apply to the restarted workflow invocation.
|
|
109
|
+
Defaults to `3` if not provided.
|
|
110
|
+
</ParamField>
|
|
111
|
+
|
|
112
|
+
## Response
|
|
113
|
+
|
|
114
|
+
<ResponseField name="cursor" type="string">
|
|
115
|
+
A pagination cursor. If not returned, all matching entries have been processed.
|
|
116
|
+
</ResponseField>
|
|
117
|
+
|
|
118
|
+
<ResponseField name="workflowRuns" type="object[]">
|
|
119
|
+
<Expandable defaultOpen>
|
|
120
|
+
<ResponseField name="workflowRunId" type="string">
|
|
121
|
+
The ID of the new workflow run created from the restarted DLQ message.
|
|
122
|
+
</ResponseField>
|
|
123
|
+
|
|
124
|
+
<ResponseField name="workflowCreatedAt" type="number">
|
|
125
|
+
The Unix timestamp (in milliseconds) when the new workflow run was created.
|
|
126
|
+
</ResponseField>
|
|
127
|
+
</Expandable>
|
|
128
|
+
</ResponseField>
|
|
129
|
+
|
|
130
|
+
## Usage
|
|
131
|
+
|
|
132
|
+
<CodeGroup>
|
|
133
|
+
```ts Single
|
|
134
|
+
const { messages } = await client.dlq.list();
|
|
135
|
+
|
|
136
|
+
const response = await client.dlq.restart(messages[0].dlqId, {
|
|
137
|
+
flowControl: {
|
|
138
|
+
key: "my-flow-control-key",
|
|
139
|
+
parallelism: 10,
|
|
140
|
+
},
|
|
141
|
+
retries: 3,
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
```ts Multiple
|
|
145
|
+
const response = await client.dlq.restart(["dlq-12345", "dlq-67890"]);
|
|
146
|
+
```
|
|
147
|
+
```ts By filters
|
|
148
|
+
let cursor: string | undefined;
|
|
149
|
+
do {
|
|
150
|
+
const result = await client.dlq.restart({
|
|
151
|
+
filter: { label: "my-label" },
|
|
152
|
+
cursor,
|
|
153
|
+
});
|
|
154
|
+
cursor = result.cursor;
|
|
155
|
+
} while (cursor);
|
|
156
|
+
```
|
|
157
|
+
```ts All
|
|
158
|
+
let cursor: string | undefined;
|
|
159
|
+
do {
|
|
160
|
+
const result = await client.dlq.restart({ all: true, cursor });
|
|
161
|
+
cursor = result.cursor;
|
|
162
|
+
} while (cursor);
|
|
163
|
+
```
|
|
164
|
+
</CodeGroup>
|