What's the cleanest way to implement "force flow c...
# ask-community
g
What's the cleanest way to implement "force flow cancellation after task completed"? I don't want to contaminate flow & task code because it's related to separate A/B testing thing, not business logic. I tried hooking task's on complete, then cancel the flow but it still keeps running:
Copy code
result = await client.set_flow_run_state(
    flow_run_id,
    Cancelled(message=f"Requested by completion hook of task '{task.name}'"),
    force=True,
)
I tried doing sys.exit(1) after cancelling, didn't help. I tried os.exit(1), it works, but it's suitable only for 1 item to processes, not for multiple items.
a
Hey @Gintas! If this is to cancel a flow run that is created from a deployment, you can set the state to
Cancelling
. That will engage the cancellation mechanics for the flow run and should cause it to shut down.