Jack P
11/13/2023, 3:23 PMMarvin
11/13/2023, 3:24 PMprefect flow-run cancel
CLI command, passing the ID of the flow run. For example:
prefect flow-run cancel 'a55a4804-9e3c-4042-8b59-b3b6b7618736'
2. Cancel via the UI: Navigate to the flow run's detail page in the UI and click the Cancel button in the upper right corner.
When cancellation is requested, the flow run is moved to a "Cancelling" state. The agent monitors the state of flow runs and detects that cancellation has been requested. The agent then sends a signal to the flow run infrastructure, requesting termination of the run. If the run does not terminate after a grace period (default of 30 seconds), the infrastructure will be killed, ensuring the flow run exits.
Please note that this process is robust to agent restarts, but does require that an agent is running to enforce cancellation.
Also, make sure to enable the experimental cancellation feature by setting the following configuration:
prefect config set PREFECT_EXPERIMENTAL_ENABLE_ENHANCED_CANCELLATION=True
If you encounter any issues, please let the Prefect team know in Slack or with a Github issue.Jack P
11/13/2023, 3:24 PMMarvin
11/13/2023, 3:25 PMcancel_flow_run
function from the Prefect API. Here is an example:
from prefect import Client
client = Client()
client.cancel_flow_run(flow_run_id="a55a4804-9e3c-4042-8b59-b3b6b7618736")
In the above code, replace "a55a4804-9e3c-4042-8b59-b3b6b7618736"
with the ID of your flow run.
To cancel a running flow run using the REST API, you can make a POST request to the /flow_run/{id}/cancel
endpoint. Here is an example using `curl`:
bash
curl -X POST "<http://localhost:4200/flow_run/a55a4804-9e3c-4042-8b59-b3b6b7618736/cancel>"
Again, replace "a55a4804-9e3c-4042-8b59-b3b6b7618736"
with the ID of your flow run.
Please note that the REST API endpoint might be different depending on your Prefect deployment. Replace localhost:4200
with your Prefect API's address.
Please let me know if you need further assistance.Jack P
11/13/2023, 3:26 PMMarvin
11/13/2023, 3:26 PMJack P
11/13/2023, 3:27 PMMarvin
11/13/2023, 3:27 PMJack P
11/13/2023, 3:29 PMset_flow_run_state
cancel a flow run?Marvin
11/13/2023, 3:30 PMset_flow_run_state
method to cancel a flow run. This method allows you to set the state of a flow run to any valid Prefect state, including the Cancelled
state.
Here is an example of how you can use this method to cancel a flow run:
from prefect import Client
from prefect.engine.state import Cancelled
client = Client()
client.set_flow_run_state(flow_run_id="a55a4804-9e3c-4042-8b59-b3b6b7618736", version=1, state=Cancelled(message="Cancelled manually"))
In the above code, replace "a55a4804-9e3c-4042-8b59-b3b6b7618736"
with the ID of your flow run and version
with the current version of your flow run state. The state
parameter is set to Cancelled
to cancel the flow run.
Please note that this method will only set the state of the flow run in the Prefect database. It will not send a signal to the executing job to stop. The job will continue to run until completion, but its results will not be reported back to Prefect because the flow run state is set to Cancelled
.
Also, please be aware that this is a low-level operation that directly manipulates the state of a flow run. It should be used with caution, as it can potentially leave your system in an inconsistent state if not used properly.Jack P
11/13/2023, 3:30 PMJack P
11/13/2023, 3:54 PM