> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# cancellation_cleanup

# `prefect.server.services.cancellation_cleanup`

The CancellationCleanup service. Responsible for cancelling tasks and subflows that haven't finished.

## Functions

### `cancelling_timeout_check_key` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation\_cleanup.py#L53](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation_cleanup.py#L53)</sup>

```python theme={null}
cancelling_timeout_check_key(flow_run_id: UUID) -> str
```

### `schedule_cancelling_timeout_check` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation\_cleanup.py#L57](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation_cleanup.py#L57)</sup>

```python theme={null}
schedule_cancelling_timeout_check() -> None
```

### `maybe_schedule_cancelling_timeout_check_for_state` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation\_cleanup.py#L75](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation_cleanup.py#L75)</sup>

```python theme={null}
maybe_schedule_cancelling_timeout_check_for_state() -> None
```

### `cancel_child_task_runs` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation\_cleanup.py#L101](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation_cleanup.py#L101)</sup>

```python theme={null}
cancel_child_task_runs(flow_run_id: Annotated[UUID, Logged]) -> None
```

Cancel child task runs of a cancelled flow run (docket task).

### `cancel_subflow_run` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation\_cleanup.py#L132](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation_cleanup.py#L132)</sup>

```python theme={null}
cancel_subflow_run(subflow_run_id: Annotated[UUID, Logged]) -> None
```

Cancel a subflow run whose parent flow run was cancelled (docket task).

### `handle_cancelling_timeout` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation\_cleanup.py#L194](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation_cleanup.py#L194)</sup>

```python theme={null}
handle_cancelling_timeout(flow_run_id: Annotated[UUID, Logged], flow_run_state_id: Annotated[UUID, Logged], timeout_cancelled_state_id: Annotated[UUID, Logged]) -> CleanupQueueMessage | None
```

Handle a scheduled CANCELLING timeout check for a single flow run.

### `ensure_cancelling_timeout_checks` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation\_cleanup.py#L372](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation_cleanup.py#L372)</sup>

```python theme={null}
ensure_cancelling_timeout_checks(docket: Docket = CurrentDocket(), db: PrefectDBInterface = Depends(provide_database_interface), perpetual: Perpetual = Perpetual(automatic=True, every=datetime.timedelta(seconds=get_current_settings().server.services.cancellation_cleanup.loop_seconds))) -> None
```

Seed Docket timeout checks for flow runs already in CANCELLING.

### `monitor_cancelled_flow_runs` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation\_cleanup.py#L447](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation_cleanup.py#L447)</sup>

```python theme={null}
monitor_cancelled_flow_runs(docket: Docket = CurrentDocket(), db: PrefectDBInterface = Depends(provide_database_interface), perpetual: Perpetual = Perpetual(automatic=True, every=datetime.timedelta(seconds=get_current_settings().server.services.cancellation_cleanup.loop_seconds))) -> None
```

Monitor for cancelled flow runs and schedule child task cancellation.

### `monitor_subflow_runs` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation\_cleanup.py#L496](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/services/cancellation_cleanup.py#L496)</sup>

```python theme={null}
monitor_subflow_runs(docket: Docket = CurrentDocket(), db: PrefectDBInterface = Depends(provide_database_interface), perpetual: Perpetual = Perpetual(automatic=True, every=datetime.timedelta(seconds=get_current_settings().server.services.cancellation_cleanup.loop_seconds))) -> None
```

Monitor for subflow runs that need to be cancelled.
