SameerMesiah97 opened a new pull request, #77562:
URL: https://github.com/apache/airflow/pull/77562

   **Description**
   
   Introduce a new `BaseTrigger.on_timeout()` lifecycle hook to allow triggers 
to clean up external resources when a deferred task exceeds its 
`execution_timeout`.
   
   Update the scheduler and triggerer to distinguish execution timeouts from 
user-initiated cancellations and trigger reassignment. The triggerer invokes 
`on_timeout()` for execution timeouts, `on_kill()` for user cancellations, and 
preserves the existing cleanup behaviour.
   
   Add timeout cancellation tracking to the `Trigger` model so that triggers 
awaiting timeout cleanup are not prematurely removed.
   
   **Rationale**
   
   Previously, when a deferred task exceeded its `execution_timeout`, its 
trigger could be removed without giving it an opportunity to cancel the 
associated external operation. This could leave external jobs running after the 
Airflow task had failed.
   
   The new lifecycle hook provides a dedicated mechanism for timeout-specific 
cleanup while keeping it separate from user-initiated cancellation and normal 
trigger cleanup.
   
   **Tests**
   
   - Added tests to `test_scheduler_job_runner.py` to verify that execution 
timeouts mark the associated triggers for timeout cleanup and correctly handle 
deferred task failures.
   
   - Added tests to `test_triggerer_job_runner.py` to verify that 
`on_timeout()` is invoked for execution timeouts, `on_kill()` is invoked for 
user cancellations, and cancellation hooks are skipped when triggers are 
reassigned.
   
   - Added tests to `test_trigger.py` to verify that triggers awaiting timeout 
cleanup are preserved and prioritised during trigger selection.
   
   - Added a test to `test_base.py` to verify that the default 
`BaseTrigger.on_timeout()` implementation is a no-op.
   
   **Migration**
   
   Added an Alembic migration introducing a nullable `cancel_reason` column to 
the `trigger` table to track triggers awaiting timeout-specific cleanup.
   
   **Documentation**
   
   Added a `feature` newsfragment documenting the new trigger timeout lifecycle 
hook and its support for cleanup when deferred tasks exceed their execution 
timeout.
   
   ###### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: [GPT 6.1] following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] Add BaseTrigger.on_timeo... SameerMesiah97 (via GitHub) via commits

Reply via email to