|
2 | 2 | title: "client.cancel" |
3 | 3 | --- |
4 | 4 |
|
5 | | -There are multiple ways you can cancel workflow runs: |
6 | | - |
7 | | -- Pass one or more workflow run ids to cancel them |
8 | | -- Pass a workflow url to cancel all runs starting with this url |
9 | | -- cancel all pending or active workflow runs |
| 5 | +Cancel one or more workflow runs. You can pass IDs directly, use filters, or cancel all at once. |
10 | 6 |
|
11 | 7 | ## Arguments |
12 | 8 |
|
13 | | -<ParamField body="ids" type="array"> |
14 | | - The set of workflow run IDs you want to cancel |
| 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" optional> |
| 35 | + Cancel workflows with this label. |
| 36 | + </ParamField> |
| 37 | + |
| 38 | + <ParamField body="fromDate" type="Date | number" optional> |
| 39 | + Cancel workflows created after this date. Accepts `Date` objects or Unix timestamps (ms). |
| 40 | + </ParamField> |
| 41 | + |
| 42 | + <ParamField body="toDate" type="Date | number" optional> |
| 43 | + Cancel workflows created before this date. Accepts `Date` objects or Unix timestamps (ms). |
| 44 | + </ParamField> |
| 45 | + |
| 46 | + <ParamField body="callerIp" type="string" optional> |
| 47 | + Cancel workflows triggered by this IP address. |
| 48 | + </ParamField> |
| 49 | + |
| 50 | + <ParamField body="flowControlKey" type="string" optional> |
| 51 | + Cancel workflows with this flow control key. |
| 52 | + </ParamField> |
| 53 | + </Expandable> |
15 | 54 | </ParamField> |
16 | 55 |
|
17 | | -<ParamField body="urlStartingWith" type="string"> |
18 | | - The URL address you want to filter while canceling |
| 56 | +<ParamField body="count" type="number" optional> |
| 57 | + Maximum number of workflow runs to cancel per call. Defaults to `100`. |
19 | 58 | </ParamField> |
20 | 59 |
|
21 | | -<ParamField body="all" type="bool"> |
22 | | - Whether you want to cancel all workflow runs without any filter. |
| 60 | +### Cancel all |
| 61 | + |
| 62 | +<ParamField body="all" type="boolean"> |
| 63 | + Set to `true` to cancel all pending and active workflow runs. |
23 | 64 | </ParamField> |
24 | 65 |
|
| 66 | +## Response |
| 67 | + |
| 68 | +<ResponseField name="cancelled" type="number"> |
| 69 | + The number of workflow runs that were cancelled. |
| 70 | +</ResponseField> |
| 71 | + |
25 | 72 | ## Usage |
26 | 73 |
|
27 | | -### Cancel a set of workflow runs |
| 74 | +### Cancel by ID |
28 | 75 |
|
29 | 76 | ```ts |
30 | 77 | // cancel a single workflow |
31 | | -await client.cancel({ ids: "<WORKFLOW_RUN_ID>" }); |
| 78 | +await client.cancel("<WORKFLOW_RUN_ID>"); |
32 | 79 |
|
33 | 80 | // cancel a set of workflow runs |
34 | | -await client.cancel({ ids: ["<WORKFLOW_RUN_ID_1>", "<WORKFLOW_RUN_ID_2>"] }); |
| 81 | +await client.cancel(["<WORKFLOW_RUN_ID_1>", "<WORKFLOW_RUN_ID_2>"]); |
35 | 82 | ``` |
36 | 83 |
|
37 | | -### Cancel workflow runs with URL filter |
| 84 | +### Cancel with URL filter |
38 | 85 |
|
39 | | -If you have an endpoint called `https://your-endpoint.com` and you |
40 | | -want to cancel all workflow runs on it, you can use `urlStartingWith`. |
| 86 | +Cancel all workflow runs on a specific endpoint using a URL prefix: |
| 87 | + |
| 88 | +```ts |
| 89 | +await client.cancel({ |
| 90 | + filter: { workflowUrlStartingWith: "https://your-endpoint.com" } |
| 91 | +}); |
| 92 | +``` |
41 | 93 |
|
42 | | -Note that this will cancel workflows in all endpoints under |
43 | | -`https://your-endpoint.com`. |
| 94 | +For an exact URL match: |
44 | 95 |
|
45 | 96 | ```ts |
46 | | -await client.cancel({ urlStartingWith: "https://your-endpoint.com" }); |
| 97 | +await client.cancel({ |
| 98 | + filter: { workflowUrl: "https://your-endpoint.com/api/workflow" } |
| 99 | +}); |
47 | 100 | ``` |
48 | 101 |
|
49 | | -### Cancel _all_ workflows |
| 102 | +### Cancel with filters |
| 103 | + |
| 104 | +You can combine multiple filter parameters: |
| 105 | + |
| 106 | +```ts |
| 107 | +// cancel by label |
| 108 | +await client.cancel({ filter: { label: "my-label" } }); |
| 109 | + |
| 110 | +// cancel by label and date range |
| 111 | +await client.cancel({ |
| 112 | + filter: { |
| 113 | + label: "my-label", |
| 114 | + fromDate: 1640995200000, |
| 115 | + } |
| 116 | +}); |
| 117 | + |
| 118 | +// cancel by URL and date range |
| 119 | +await client.cancel({ |
| 120 | + filter: { |
| 121 | + workflowUrl: "https://your-endpoint.com/api/workflow", |
| 122 | + fromDate: new Date("2024-01-01"), |
| 123 | + toDate: new Date("2024-06-01"), |
| 124 | + } |
| 125 | +}); |
| 126 | +``` |
50 | 127 |
|
51 | | -To cancel all pending and currently running workflows, you can |
52 | | -do it like this: |
| 128 | +### Cancel _all_ workflows |
53 | 129 |
|
54 | 130 | ```ts |
55 | | -await client.cancel({ all: true }); |
| 131 | +let cancelled: number; |
| 132 | +do { |
| 133 | + const result = await client.cancel({ all: true }); |
| 134 | + cancelled = result.cancelled; |
| 135 | +} while (cancelled > 0); |
56 | 136 | ``` |
0 commit comments