cmarteepants commented on code in PR #70225:
URL: https://github.com/apache/airflow/pull/70225#discussion_r4444226006


##########
providers/standard/docs/sensors/asset.rst:
##########
@@ -0,0 +1,304 @@
+ .. 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.
+
+Supply at least one query filter: ``after``, ``before``, ``partition_key``,
+``partition_key_regexp_pattern``, or a non-empty ``extra`` dictionary. The 
sensor
+raises ``ValueError`` at construction if no filter is supplied. It checks again
+after template rendering, before querying events. An empty ``extra={}`` does
+not count as a filter.
+
+Time bounds are optional when another query filter is supplied. Ordering,
+``limit``, and ``process_result`` do not replace query filters.
+
+This daily example waits for events at or after the data interval ends:
+
+.. 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]
+
+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``:
+
+.. list-table:: Choosing a time bound
+    :header-rows: 1
+    :widths: 20 25 25 30
+
+    * - Bound
+      - Available on
+      - When tasks are cleared
+      - Watch out for
+    * - ``RunStart()``
+      - All runs, including asset-triggered runs and backfills.
+      - A finished run gets a new start time when it starts again. Clearing 
tasks
+        in a queued or running run preserves the existing start time.
+      - Uses ``dag_run.start_date``, the actual start even for a backfill.
+        With ``after``, a negative offset can include events from an earlier 
execution.
+    * - ``RunAfter()``
+      - All runs, including asset-triggered runs and backfills.
+      - Stays fixed for the same run.
+      - Uses ``dag_run.run_after``. For some asset timetables, this equals a
+        triggering event's timestamp. Since ``after`` is inclusive, that event
+        can satisfy the sensor immediately.
+    * - ``LogicalDate()``
+      - Runs with a logical date, including manual runs that supply one.
+        Asset-triggered runs have none.
+      - Stays fixed for the same run.
+      - Its meaning depends on the timetable or the value supplied for a manual
+        run. It does not necessarily represent when execution started.
+    * - ``DataIntervalStart()`` / ``DataIntervalEnd()``
+      - Runs with a data interval. Availability depends on the timetable and
+        run type. Asset-triggered runs have none.
+      - Stay fixed for the same run.
+      - Use the interval represented by the run for historical work.
+        ``CronTriggerTimetable`` defaults to a zero-length interval, so both
+        bounds are equal.
+
+Use ``after=RunStart()`` when clearing a finished run should wait for new data.
+Use ``after=RunAfter()`` to keep the same time boundary when an asset-triggered
+run is cleared. Runs with logical dates or data intervals can also use those
+fixed bounds. An open-ended query can still include new events that arrive
+later, so fixed bounds do not freeze the result set.
+
+Each built-in object accepts a signed ``offset`` duration, with zero as the
+default. A negative offset moves the bound earlier. A positive offset moves it
+later. For example, ``after=DataIntervalEnd(offset=-timedelta(hours=1))`` 
includes
+events from one hour before the interval ends onward.
+``before=DataIntervalEnd(offset=timedelta(hours=1))`` includes events up to one
+hour after the interval ends. Import ``timedelta`` from ``datetime`` to use 
these
+examples.
+
+To exclude events exactly at ``dag_run.run_after``, use
+``after=RunAfter(offset=timedelta(microseconds=1))``. Later events can still 
match,
+including events seen during an earlier execution of the run.
+
+For example, use both interval bounds to select a historical window:
+
+.. 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.
+
+To create a nonzero window with ``CronTriggerTimetable``, use an offset or
+configure the timetable's ``interval``.
+
+A bound raises ``ValueError`` if its selected timestamp is missing; it does not
+substitute another timestamp. Manual runs can have a data interval when a 
logical
+date is supplied. Use ``after=RunStart()`` to wait for events at or after the 
actual
+start of an asset-triggered run.

Review Comment:
   Small nit. I'd replace 
   >Use ``after=RunStart()`` to wait for events at or after the actual
   start of an asset-triggered run.
   
   with
    
   > For asset-triggered runs, use `RunStart()` or `RunAfter()` instead. See 
the table for how they differ when a run is cleared. 
   
   I think the paragraph came before `RunAfter()`.



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