There are multiple ways you can cancel workflow runs:
- Pass one or more workflow run ids to cancel them
- Pass a workflow url to cancel all runs with this exact url
- Pass a url prefix to cancel all runs starting with this url
- Pass filters (label, date range) to cancel matching workflow runs
- Cancel all pending or active workflow runs (by calling without any parameters)
Arguments
The set of workflow run IDs you want to cancel.
The exact URL of workflows you want to cancel.
The URL prefix to filter workflows while canceling. All workflows with URLs
starting with this prefix will be canceled.
Cancel workflows with this label.
Cancel workflows created after this date (Unix ms as string).
Cancel workflows created before this date (Unix ms as string).
Deprecated: If no parameters are provided, all workflows will be cancelled
by default.
Returns
Returns an object with the number of cancelled workflows:
Usage
Cancel a set of workflow runs
// cancel a single workflow
const result = await client.cancel({ ids: "<WORKFLOW_RUN_ID>" });
console.log(`Cancelled ${result.cancelled} workflow(s)`);
// cancel a set of workflow runs
const result = await client.cancel({
ids: ["<WORKFLOW_RUN_ID_1>", "<WORKFLOW_RUN_ID_2>"],
});
console.log(`Cancelled ${result.cancelled} workflow(s)`);
Cancel workflow runs with exact URL
Cancel all workflow runs with a specific URL:
const result = await client.cancel({
workflowUrl: "https://your-endpoint.com/api/workflow",
});
console.log(`Cancelled ${result.cancelled} workflow(s)`);
Cancel workflow runs with URL prefix
If you have an endpoint called https://your-endpoint.com and you
want to cancel all workflow runs on it, you can use urlStartingWith.
Note that this will cancel workflows in all endpoints under
https://your-endpoint.com.
const result = await client.cancel({
urlStartingWith: "https://your-endpoint.com",
});
console.log(`Cancelled ${result.cancelled} workflow(s)`);
Cancel workflow runs with filters
Cancel all active workflows that match the provided filters:
// cancel workflows with a specific label
const result = await client.cancel({
label: "my-workflow-label",
});
// cancel workflows within a date range
const result = await client.cancel({
fromDate: "1640995200000",
toDate: "1672531200000",
});
// combine multiple filters
const result = await client.cancel({
label: "my-workflow-label",
fromDate: "1640995200000",
toDate: "1672531200000",
});
console.log(`Cancelled ${result.cancelled} workflow(s)`);
Cancel all workflows
To cancel all pending and currently running workflows, simply call cancel without any parameters:
const result = await client.cancel({});
console.log(`Cancelled ${result.cancelled} workflow(s)`);