hussein-awala commented on code in PR #70225:
URL: https://github.com/apache/airflow/pull/70225#discussion_r4406930318


##########
providers/standard/docs/sensors/asset.rst:
##########
@@ -0,0 +1,243 @@
+ .. Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+ ..   http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+
+
+.. _howto/sensor:AssetEventSensor:
+
+AssetEventSensor
+================
+
+Use the :class:`~airflow.providers.standard.sensors.asset.AssetEventSensor` to 
wait for
+asset events matching a set of filters to reach an expected count.
+
+Use this sensor when an already-running Dag needs an asset between tasks. For 
example, a
+daily consumer can run its preparation tasks immediately, then wait for 
another Dag to
+produce the partition for its own data interval. Moving that dependency to an 
asset schedule
+would change when the entire Dag starts and the data interval used by the 
consumer.
+
+The sensor declares its target as an inlet, so the dependency is visible in 
asset lineage
+without changing the Dag's schedule. It reads events through 
``context["inlet_events"]``.
+
+.. note::
+
+    This sensor requires **Apache Airflow 3.2+**. The ``partition_key``,
+    ``partition_key_regexp_pattern`` and ``extra`` filters require
+    **Apache Airflow 3.4+**.
+
+When to use a schedule instead
+------------------------------
+
+If the dependency does not need to sit in the middle of a run, a schedule is
+usually a better fit. See
+:doc:`apache-airflow:authoring-and-scheduling/asset-scheduling` for details.
+
+* Schedule the Dag on the asset when the whole run can wait for it.
+* Use ``AssetAndTimeSchedule`` (Airflow 3.4+) when a time-scheduled run needs
+  the asset before it starts.
+* Use a partitioned asset timetable with ``RollupMapper`` to wait for every
+  partition in a window.
+
+Use this sensor when some tasks should run immediately and only later tasks
+depend on the asset. Here, ``prepare`` starts as soon as the run does, and only
+``process`` waits for the partition (``wait_for_partition_events`` is defined
+:ref:`below <howto/sensor:AssetEventSensor:filtering>`):
+
+.. exampleinclude:: 
/../src/airflow/providers/standard/example_dags/example_asset_sensor.py
+    :language: python
+    :dedent: 4
+    :start-after: [START example_asset_event_sensor_mid_run]
+    :end-before: [END example_asset_event_sensor_mid_run]
+
+Basic usage
+-----------
+
+Pass an :class:`~airflow.sdk.Asset`, :meth:`~airflow.sdk.Asset.ref`, or
+:class:`~airflow.sdk.AssetAlias` as ``asset``. A reference must resolve to an
+existing asset when the task starts. The target is static so Airflow can record
+the inlet; use templated event filters to select a run's events. By default the
+sensor succeeds once **at least one** matching event exists.
+
+.. warning::
+
+    Without ``after``, ``before`` or a partition filter, the sensor considers
+    the asset's entire event history, so it succeeds immediately if a matching
+    event ever existed. Bound the query, for example by time, as below.
+
+.. exampleinclude:: 
/../src/airflow/providers/standard/example_dags/example_asset_sensor.py
+    :language: python
+    :dedent: 4
+    :start-after: [START example_asset_event_sensor]
+    :end-before: [END example_asset_event_sensor]
+
+.. note::
+
+    For asset-triggered runs, ``dag_run.run_after`` can be the timestamp of the
+    newest triggering event, and ``after`` is inclusive. If the sensor waits on
+    the same asset that triggered the run, that event satisfies it immediately.
+    Use ``RunStart()`` to wait for events at or after the actual run start.
+
+A mapped sensor works, but its asset is only recorded as an inlet in lineage if
+it is also passed through ``partial(inlets=[...])``.
+
+Run-relative time bounds
+------------------------
+
+The ``after`` and ``before`` arguments accept datetime values, ISO strings,
+Jinja templates, and these bound objects from
+``airflow.providers.standard.sensors.asset``:
+
+* ``RunStart()`` uses ``dag_run.start_date``, the actual start of the Dag run.
+* ``LogicalDate()`` uses ``logical_date``.
+* ``DataIntervalStart()`` uses ``data_interval_start``.
+* ``DataIntervalEnd()`` uses ``data_interval_end``.
+
+Each built-in object accepts a non-negative ``lookback`` duration, with zero 
as the
+default. For example, ``RunStart(lookback=timedelta(hours=1))`` includes events
+from one hour before the Dag run started. The basic example above uses this
+bound, so an event from that hour can satisfy the sensor immediately.
+
+``RunStart`` uses the actual start even for a backfill. Select a logical date
+or data interval explicitly when you need historical bounds. For example:
+
+.. code-block:: python
+
+    from airflow.providers.standard.sensors.asset import (
+        AssetEventSensor,
+        DataIntervalEnd,
+        DataIntervalStart,
+    )
+
+    wait_for_interval_events = AssetEventSensor(
+        task_id="wait_for_interval_events",
+        asset=my_asset,
+        after=DataIntervalStart(),
+        before=DataIntervalEnd(),
+    )
+
+Both bounds are inclusive and filter the asset event's timestamp. An event at
+an interval boundary can therefore match two adjacent intervals. These bounds
+do not filter the event's partition key.
+
+A bound raises ``ValueError`` if its selected timestamp is missing. For 
example,
+some runs do not have a logical date or data interval. The sensor does not
+substitute another timestamp in that case.
+
+Airflow resolves the objects during template rendering, before polling. Their
+run-relative values stay fixed while the sensor polls and after rescheduling.

Review Comment:
   I corrected the guide to distinguish clearing from rescheduling. Clearing a 
finished run gives it a new actual start time when it starts again. 
`RunStart()` therefore moves forward.
   The table contrasts this with the fixed `RunAfter()`, logical date, and 
interval bounds. The tests check each helper’s response to changed run 
metadata. They also check that reconstructed sensors keep their bounds after 
rescheduling.



-- 
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