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

    <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   <!--
   Thank you for contributing!
   
   Please provide above a brief description of the changes made in this pull 
request.
   Write a good git commit message following this guide: 
http://chris.beams.io/posts/git-commit/
   
   Please make sure that your code changes are covered with tests.
   And in case of new features or big changes remember to adjust the 
documentation.
   
   For user-facing UI changes, please attach before/after screenshots (or a 
short
   screen recording) so reviewers can assess the visual impact.
   
   Feel free to ping (in general) for the review if you do not see reaction for 
a few days
   (72 Hours is the minimum reaction time you can expect from volunteers) - we 
sometimes miss notifications.
   
   In case of an existing issue, reference it using one of the following:
   
   * closes: #ISSUE
   * related: #ISSUE
   -->
   
   ---
   
   * Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information. Note: commit author/co-author name and email in commits 
become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License 
Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: 
`{pr_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
 You can add this file in a follow-up commit after the PR is created so you 
know the PR number.
   
   ---
   
   closes: #66791
   
   When a Dag is configured with `catchup=False` and the scheduler advances
   past missed intervals (for example after a restart or re-enable), the skip
   happens silently: no DagRun rows are created and no hook fires. Operators
   who need observability for skipped partitions (SLA accounting, compliance
   audit trails, dashboard counters) had to compare 
`last_automated_data_interval`
   against wall clock externally.
   
   This PR adds two symmetric extension points:
   
   1. **`on_skipped_intervals_callback`** — a Dag-level callback on the SDK
      `DAG` constructor, using the same context-based signature as
      `on_success_callback` / `on_failure_callback`. The context includes
      `dag`, `reason` (`"skipped_intervals"`), and `skipped_intervals` (a
      list of `DataInterval` objects).
   
   2. **`on_intervals_skipped`** — an AIP-61 listener hookspec for plugins
      that need in-process observability without reloading the Dag file.
   
   ### How it works
   
   Skipped intervals are detected by **reconstruction** at scheduled DagRun
   creation time (timetable-agnostic):
   
   - When the scheduler creates a new `SCHEDULED` run for a `catchup=False`
     Dag, it compares the new run's `data_interval_start` against the
     `data_interval_end` of the most recent prior scheduled run.
   - It enumerates the gap using `SerializedDAG.iter_dagrun_infos_between`
     (which uses `catchup=True` internally) and collects intervals strictly
     between the two endpoints.
   - Detection is gated: reconstruction runs only when `not dag.catchup` AND
     (`has_on_skipped_intervals_callback` is set OR an `on_intervals_skipped`
     listener implementation is registered).
   
   **Listener** fires synchronously in the scheduler (same pattern as
   `on_dag_run_running` for Dag start events).
   
   **Callback** follows the existing Dag callback pipeline:
   `DagSkippedIntervalsCallbackRequest` → `DatabaseCallbackSink` → Dag File
   Processor reloads the Dag file and invokes the callable. Skipped intervals
   are serialized as `(start, end)` datetime pairs in the request because no
   DagRun row exists for skipped intervals and the processor cannot reliably
   reconstruct the gap later.
   
   ### Files changed
   
   | Area | Files |
   |------|-------|
   | SDK Dag definition | `task-sdk/src/airflow/sdk/definitions/dag.py` |
   | Serialization | `serialization/definitions/dag.py`, 
`serialized_objects.py`, `schema.json` |
   | Callback transport | `callbacks/callback_requests.py`, 
`dag_processing/processor.py` |
   | Listener | `listeners/spec/dag.py` (new), `listeners/listener.py` |
   | Scheduler | `jobs/scheduler_job_runner.py` |
   
   ### Usage (preview)
   
   ```python
   from airflow.sdk import DAG
   from airflow.timetables.base import DataInterval
   
   def notify_skipped(context):
     for interval in context["skipped_intervals"]:
       print(f"Skipped: {interval.start} → {interval.end}")
   
   with DAG("my_dag", schedule="@daily", catchup=False,
            on_skipped_intervals_callback=notify_skipped) as dag:
       ...
   ```
   
   ## Follow-up (Will be added to this PR)
   
   - [ ] Unit and integration tests (scheduler skip detection, callback 
execution, listener hook, serialization roundtrip)
   
   - [ ] User documentation (on_skipped_intervals_callback in Dag reference, 
on_intervals_skipped in listeners docs)
   
   - [ ] Newsfragment in airflow-core/newsfragments/ (user-facing feature)
   
   ### Test plan
   *To be completed before marking Ready for review:*
   
   - [ ] Scheduler creates skip callback request when catchup=False Dag jumps 
past intervals and callback is configured
   
   - [ ] Listener on_intervals_skipped fires with correct intervals
   
   - [ ] Dag File Processor executes callback with skipped_intervals in context
   
   - [ ] No overhead when callback and listener are both unset
   
   - [ ] Serialization roundtrip preserves has_on_skipped_intervals_callback
   
   - [ ] prek run --from-ref main --stage pre-commit passes
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, 
please
   change below checkbox to `[X]` followed by the name of the tool, uncomment 
the "Generated-by".
   -->
   
   - [X] Yes - Cursor (Auto)
   Generated-by: Cursor (Auto) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   <!--
   Generated-by: [Tool Name] 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]

Reply via email to