Repository navigation
How to cleanup cancel/kill/cleanup running or finished workflow #655
|
I couldnt find this in the document but I am looking for a way to easily kill/clean/cancel running or finished workflows.. and clear all data.. preferably programmaticly. |
Replies: 1 comment 1 reply
|
Hey @roanschuurman, hope you're doing well! Good question, and you're right that it's spread across a few pages, so it's easy to miss. To stop a run from code, use Here's where that comes from on
A small example: import { getRun, start } from "workflow/api";
import { myWorkflow } from "./workflows/my-workflow";
export async function startThrowaway(input: string) {
return start(myWorkflow, [input], { experimental_retention: 0 });
}
export async function cancelRun(runId: string) {
await getRun(runId).cancel({ cancelReason: "cancelled by user" });
}And from the terminal: npx workflow cancel <runId>
npx workflow cancel --status=running --workflowName=myWorkflow -yI checked these against
Does that fit your setup? I wasn't sure if you're on the Local World, Vercel or Postgres, so I'd love to know which one, since "clear all data" works a bit differently on each. And if any maintainers or folks here have a nicer way to fully purge finished runs, I'd really appreciate the tips! |

Hey @roanschuurman, hope you're doing well! Good question, and you're right that it's spread across a few pages, so it's easy to miss.
To stop a run from code, use
getRun(runId).cancel()fromworkflow/api, orworkflow cancel <runId>from the CLI (it can also bulk cancel by status or workflow name). For clearing data, there's no "delete this run" call today; the closest thing is starting a run withexperimental_retention: 0, which wipes its payloads as soon as it finishes, and on the Local World you can just delete the.workflow-datafolder.Here's where that comes from on
main:getRunis exported fromworkflow/api(api.ts#L30-L36), andRun.cancel()takes an optionalcan…