<@ULVA73B9P> how to cancel a flow by flow name if ...
# ask-marvin
e
@Marvin how to cancel a flow by flow name if the UI dashboard is showing the cancel button grayed out?
m
thought for 166.7 seconds
Short answer: you can’t cancel “by name” directly — you cancel specific flow runs by ID. The UI button is greyed out when the run isn’t in a cancellable state (e.g., already finished), or you don’t have permission. Here’s how to do it from the CLI: 1) List the relevant runs for your flow name and find the ID(s):
Copy code
prefect flow-run ls --flow-name "YOUR_FLOW_NAME" --state RUNNING --limit 20
2) Cancel the run by ID:
Copy code
prefect flow-run cancel <FLOW_RUN_ID>
Tips if the button is greyed out: - Only runs in active states (e.g., RUNNING, sometimes PENDING/SCHEDULED) can be cancelled. - If it’s already CANCELLING/CANCELLED/COMPLETED/FAILED/CRASHED, the button will be disabled. - In Cloud, you may need sufficient permissions to cancel runs. - Cancellation is best-effort. If the infra is hung, you may need to kill the process/pod/container directly (e.g., delete the Kubernetes pod or Docker container).
e
@Marvin what if I'm running prefect with a postgreSQL database on http://localhost:4200 ?
m
thought for 200.1 seconds
If you’re running a self-hosted Prefect Server (backed by Postgres) at http://localhost:4200, the process is the same — you just need your CLI pointed at the local API and then cancel by flow run ID. Key bits: - The API URL is at http://localhost:4200/api (include the /api). The UI at 4200 without /api won’t help your CLI. Configure your CLI to hit your local server: - One-off for the current shell:
Copy code
export PREFECT_API_URL=<http://localhost:4200/api>
- Or persist it in your Prefect profile:
Copy code
prefect config set PREFECT_API_URL=<http://localhost:4200/api>
- Double-check:
Copy code
prefect config view
Then list and cancel by ID:
Copy code
prefect flow-run ls --flow-name "YOUR_FLOW_NAME" --state RUNNING --limit 50
prefect flow-run cancel <FLOW_RUN_ID>
If the UI cancel button is still greyed out: - The run likely isn’t in a cancellable state (already finished or already cancelling). - If it’s genuinely stuck, cancellation is best-effort. Kill the underlying process/container: - Local process: terminate the Python process. - Docker: docker kill <container> - Kubernetes: kubectl delete pod <pod> And if things feel out of sync, you can restart your local server (disruptive, obviously):
Copy code
prefect server stop
prefect server start
If you want, tell me the flow name and I’ll give you an exact command sequence to target the latest RUNNING run.