The Prefect cancellation service is designed to stop running flow executions. Here's how it works:
1.
Infrastructure Identification: Prefect identifies the infrastructure running a flow using unique identifiers. These identifiers vary based on the type of infrastructure:
-
Processes: Identified by the machine's hostname and the process ID (PID).
-
Docker Containers: Identified by the Docker API URL and the container ID.
-
Kubernetes Jobs: Identified by the Kubernetes cluster name and the job name.
2.
Scope Management: Prefect uses these identifiers within a specific scope to ensure it cancels the correct infrastructure. This is crucial when multiple workers are running on different machines, potentially having overlapping PIDs.
3.
Cancellation Process: Once a cancellation request is made, Prefect attempts to terminate the flow run by interacting with the infrastructure directly. If the infrastructure supports cancellation, Prefect will proceed to stop the flow.
4.
Potential Issues:
- If the infrastructure does not support cancellation, the process will not work.
- If the identifier scope does not match, the worker may not be able to cancel the flow run, and another worker might attempt cancellation.
- If the infrastructure cannot be found or has already been terminated, the flow run is marked as cancelled.
- If the infrastructure PID is missing, the flow run is marked as cancelled, but enforcement of cancellation might not be possible.
For more detailed information, you can refer to the
Prefect documentation on cancellation.