Mitch
06/05/2024, 9:27 PMMarvin
06/05/2024, 9:27 PMrun_deployment
) cannot be cancelled independently of their parent flow. If the parent flow is cancelled, the inline subflows will also be cancelled.
- Behavior: These subflows behave as tasks within the parent flow, so when the parent flow's state changes to cancelling or cancelled, the subflows will follow suit.
2. Subflows via run_deployment
:
- Cancellation: Subflows started using run_deployment
with timeout=0
can outlive their parent flow run if not explicitly handled.
- Behavior: If the parent flow is cancelled, these subflows may continue running unless specific logic is implemented to handle their cancellation. This means such subflows might need to be cancelled manually unless you use enhanced cancellation features.
### Enhanced Cancellation
Prefect has an experimental setting to improve cancellation behavior. You can enable it by setting:
shell
prefect config set PREFECT_EXPERIMENTAL_ENABLE_ENHANCED_CANCELLATION=True
### Example Code
Here’s a small example of defining a parent and its subflow:
python
from prefect import flow, task
@task
def print_hello(name):
msg = f"Hello {name}!"
print(msg)
return msg
@flow
def my_subflow(msg):
print(f"Subflow says: {msg}")
@flow
def hello_world(name="world"):
message = print_hello(name)
my_subflow(message)
hello_world("Marvin")
### Issues and Discussions
Two issues highlight ongoing work and discussion around cascading cancellations for subflows:
1. Support subflow cancellation if parent flow is in terminal state
2. Cascading cancellation should work for normal subflows, not just sub-deployments
For more details, you can refer to the Prefect documentation on flows.
In summary, cancellation of a parent flow typically cascades down to its subflows unless specific deployment and execution settings are configured to handle otherwise.Mitch
06/05/2024, 9:30 PMMarvin
06/05/2024, 9:30 PMPREFECT_API_SERVICES_CANCELLATION_CLEANUP_LOOP_SECONDS
environment variable controls the frequency at which the cancellation cleanup service runs in Prefect. This service is responsible for cleaning up and marking flow runs and task runs as cancelled when appropriate. By default, it is set to 20 seconds, meaning the cleanup service will check for cancellation tasks every 20 seconds.
### Relevant Information:
- Default Value: 20.0 seconds
- Purpose: To control the interval for cancellation cleanup operations.
- Related Issues:
- CancellationCleanup service locking up DB: Describes potential database locking issues with the CancellationCleanup service.
- Enhance documentation on Prefect Settings: Requests better documentation for various settings, including cancellation cleanup.
### Usage Example:
To modify the default cleanup frequency, set the environment variable as follows:
shell
export PREFECT_API_SERVICES_CANCELLATION_CLEANUP_LOOP_SECONDS=30
This configuration will adjust the service to run its cleanup loop every 30 seconds.
### Additional Context:
For complex setups where many flow runs and subflows are managed, tweaking this setting can help balance cleanup performance and database load. If the cleanup interval is too frequent, it might lead to performance issues, whereas setting it to a longer interval delays the cleanup operations.
For more comprehensive information on Prefect settings, you can refer to the Prefect documentation on concepts.