I’ll occasionally encounter a flow run that is stuck in a running or late state that I want to cancel. When I open the flow run in the UI and click “Cancel”, it will change the state to “Cancelling”, but the flow run state never changes to “Cancelled”. Is there something else I need to do either on the UI or agent side of things?
1 Like
Hello,
I occasionally run into the same issue, I’d advise you to check your Agent logs, in my case the Agent continuously attempted to terminate the ‘Cancelling’ flow to the point where it became so busy it was unable to start new flow runs. (You’ll also get the Flow ID from there if it’s no longer in the UI.)
You can terminate a flow easily via the API if you have its ID:
import asyncio
from prefect.client import get_client
from prefect.server.schemas.states import Cancelled
async def main(flow_id):
async with get_client() as client:
response = await client.set_flow_run_state(flow_run_id=flow_id, state=Cancelled())
print(response)
Hope this helps
1 Like