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

   **Description**
   
   **Note: This PR is currently intended as a proof of concept and is not 
intended to be reviewed with the intention of merging. AIP-121 is still in the 
DISCUSSION phase, and the proposed design and implementation remain subject to 
change based on community feedback.**
   
   Introduce `PollingTrigger`, a reusable base class for polling-based triggers 
in Airflow Core, as part of [AIP-121: Introduce a PollingTrigger Lifecycle 
Framework](https://cwiki.apache.org/confluence/spaces/AIRFLOW/pages/451974742/AIP-121+Introduce+a+PollingTrigger+Lifecycle+Framework)
   
   This PR implements the Core framework described in the [AIP-121 Appendix: 
Reference 
Implementation](https://cwiki.apache.org/confluence/spaces/AIRFLOW/pages/462817381/AIP-121+Appendix+Reference+Implementation).
   
   `PollingTrigger` extends `BaseTrigger` and provides a standard polling 
lifecycle, including polling intervals, retries, deadline handling and terminal 
event emission.
   
   Subclasses implement `poll()`, returning `None` to continue polling or a 
`TriggerEvent` when a terminal condition is reached. The framework manages the 
polling loop, allowing providers to focus on API-specific status checks and 
event payloads.
   
   Optional hooks allow providers to classify retryable exceptions and 
customise error and timeout events.
   
   **Rationale**
   
   Polling triggers across Airflow providers frequently implement similar logic 
for polling intervals, retries, timeouts and error handling. These 
implementations are duplicated across providers and can lead to inconsistent 
behaviour.
   
   Introducing a shared polling framework reduces this duplication and provides 
consistent lifecycle handling while preserving provider-specific polling logic.
   
   `PollingTrigger` is optional, and existing triggers can continue inheriting 
directly from `BaseTrigger`.
   
   **Tests**
   
   Added unit tests verifying that:
   
   - Invalid polling intervals, retry counts and deadlines are rejected.
   - Deadlines can be serialized and reconstructed.
   - Polling continues when `poll()` returns `None` and stops when a terminal 
event is returned.
   - Non-retryable exceptions produce error events without further polling.
   - Retryable exceptions respect the configured retry budget.
   - Successful polls reset the consecutive retry counter.
   - Expired deadlines emit timeout events without invoking `poll()`.
   - Terminal events take precedence when a deadline expires during a 
successful poll.
   - Deadlines take precedence over exceptions raised during polling.
   - Polling sleeps are bounded by the remaining deadline.
   - Cancellation propagates without emitting an event.
   - `cleanup()` and `on_kill()` are not invoked by the polling loop.
   
   **Notes**
   
   - This PR introduces the Core framework for AIP-121. Provider migrations and 
compatibility support will be handled separately.
   - `PollingTrigger` does not change the existing `BaseTrigger` contract.
   - The `end_time` deadline is distinct from task-level `execution_timeout` 
and deferral timeouts.
   - Retry state is maintained in memory and resets if the trigger is 
reconstructed after a triggerer restart.
   - Provider-specific serialization, external resource cleanup and event 
payloads remain the responsibility of subclasses.
   
   **Documentation**
   
   Updated the Deferrable Operators & Triggers documentation with a section 
covering `PollingTrigger`, including its `poll()` contract, retry handling, 
deadlines, lifecycle hooks and an example implementation.
   
   ###### 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] [AIP 121] Add PollingTri... SameerMesiah97 (via GitHub) via commits

Reply via email to