Cancelling a Flow Run in the UI

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 :slightly_smiling_face:

1 Like