hussein-awala commented on code in PR #70225: URL: https://github.com/apache/airflow/pull/70225#discussion_r4406915577
########## providers/standard/src/airflow/providers/standard/example_dags/example_asset_sensor.py: ########## @@ -0,0 +1,85 @@ +# 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. +"""Example Dag demonstrating the usage of the ``AssetEventSensor``.""" + +from __future__ import annotations + +from datetime import timedelta +from typing import Any + +from airflow.providers.common.compat.sdk import AirflowOptionalProviderFeatureException +from airflow.providers.standard.version_compat import AIRFLOW_V_3_4_PLUS + +if not AIRFLOW_V_3_4_PLUS: + raise AirflowOptionalProviderFeatureException("AssetEventSensor needs Airflow 3.4+.") + +import pendulum + +from airflow.providers.standard.operators.empty import EmptyOperator +from airflow.providers.standard.sensors.asset import AssetEventSensor, RunStart +from airflow.sdk import DAG, Asset + +my_asset = Asset("s3://bucket/my-file.csv") + + +# [START example_asset_event_process_result] +def latest_event_only(events: list[Any]) -> list[Any]: + """Keep only the most recent event.""" + return events[-1:] + + +# [END example_asset_event_process_result] + + +with DAG( + dag_id="example_asset_sensor", + schedule="@daily", + start_date=pendulum.datetime(2021, 1, 1, tz="UTC"), + catchup=False, + tags=["example"], +) as dag: + # [START example_asset_event_sensor] + wait_for_asset_event = AssetEventSensor( + task_id="wait_for_asset_event", + asset=my_asset, + after=RunStart(lookback=timedelta(hours=1)), Review Comment: I changed the daily example to `after=DataIntervalEnd()`. -- 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]
