You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2020/08/14 23:53:32 UTC

[airflow] branch v1-10-test updated (ecc8e24 -> e896e83)

This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a change to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git.


    from ecc8e24  Create a short-link for Airflow Slack Invites (#10034)
     new fab690f  Add DateTimeSensor (#9697)
     new e55f9e1  Updated link to official documentation (#9629)
     new 98c8864  Add Qingping Hou to committers list (#9725)
     new e896e83  Add new committers: Ry Walker & Leah Cole to project.rst (#9892)

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 airflow/sensors/date_time_sensor.py    | 76 ++++++++++++++++++++++++++++++++++
 docs/project.rst                       |  8 ++--
 tests/sensors/test_date_time_sensor.py | 72 ++++++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+), 3 deletions(-)
 create mode 100644 airflow/sensors/date_time_sensor.py
 create mode 100644 tests/sensors/test_date_time_sensor.py


[airflow] 03/04: Add Qingping Hou to committers list (#9725)

Posted by ka...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 98c886413e1b9b673577442e2081ce6a20dc023b
Author: Tomek Urbaszek <tu...@gmail.com>
AuthorDate: Wed Jul 8 22:22:08 2020 +0200

    Add Qingping Hou to committers list (#9725)
    
    (cherry picked from commit 576100b58e555bea7731a95c19200eb927d6696b)
---
 docs/project.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/docs/project.rst b/docs/project.rst
index 5b1df44..90ad4e7 100644
--- a/docs/project.rst
+++ b/docs/project.rst
@@ -64,9 +64,9 @@ Committers
 - @milton0825 (Chao-Han Tsai)
 - @feluelle (Felix Uellendall)
 - @sekikn (Kengo Seki)
-- @nuclearpinguin (Tomasz Urbaszek)
+- @turbaszek (Tomasz Urbaszek)
 - @zhongjiajie (Jiajie Zhong)
-
+- @houqp (Qingping Hou)
 
 For the full list of contributors, take a look at `Airflow's Github
 Contributor page:


[airflow] 04/04: Add new committers: Ry Walker & Leah Cole to project.rst (#9892)

Posted by ka...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit e896e83cd713e212e8efc484b35063eda602f04a
Author: Kaxil Naik <ka...@gmail.com>
AuthorDate: Mon Jul 20 16:23:00 2020 +0100

    Add new committers: Ry Walker & Leah Cole to project.rst (#9892)
    
    (cherry picked from commit d7c996c6fe7789c8ee24a1c6e1868e05a4b33621)
---
 docs/project.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/docs/project.rst b/docs/project.rst
index 90ad4e7..41fdb65 100644
--- a/docs/project.rst
+++ b/docs/project.rst
@@ -67,6 +67,8 @@ Committers
 - @turbaszek (Tomasz Urbaszek)
 - @zhongjiajie (Jiajie Zhong)
 - @houqp (Qingping Hou)
+- @ryw (Ry Walker)
+- @leahecole (Leah Cole)
 
 For the full list of contributors, take a look at `Airflow's Github
 Contributor page:


[airflow] 01/04: Add DateTimeSensor (#9697)

Posted by ka...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit fab690f36a928c8ebaee4e46116649d38c8e9619
Author: zikun <33...@users.noreply.github.com>
AuthorDate: Fri Jul 24 00:53:10 2020 +0800

    Add DateTimeSensor (#9697)
    
    * Add DateTimeSensor
    
    (cherry picked from commit 243b704f47df00365e3421b55d8818fc9c71196f)
---
 airflow/sensors/date_time_sensor.py    | 76 ++++++++++++++++++++++++++++++++++
 tests/sensors/test_date_time_sensor.py | 72 ++++++++++++++++++++++++++++++++
 2 files changed, 148 insertions(+)

diff --git a/airflow/sensors/date_time_sensor.py b/airflow/sensors/date_time_sensor.py
new file mode 100644
index 0000000..a62f3cb8
--- /dev/null
+++ b/airflow/sensors/date_time_sensor.py
@@ -0,0 +1,76 @@
+#
+# 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.
+
+import datetime
+
+from airflow.sensors.base_sensor_operator import BaseSensorOperator
+from airflow.utils import timezone
+from airflow.utils.decorators import apply_defaults
+
+
+class DateTimeSensor(BaseSensorOperator):
+    """
+    Waits until the specified datetime.
+
+    A major advantage of this sensor is idempotence for the ``target_time``.
+    It handles some cases for which ``TimeSensor`` and ``TimeDeltaSensor`` are not suited.
+
+    **Example** 1 :
+        If a task needs to wait for 11am on each ``execution_date``. Using
+        ``TimeSensor`` or ``TimeDeltaSensor``, all backfill tasks started at
+        1am have to wait for 10 hours. This is unnecessary, e.g. a backfill
+        task with ``{{ ds }} = '1970-01-01'`` does not need to wait because
+        ``1970-01-01T11:00:00`` has already passed.
+
+    **Example** 2 :
+        If a DAG is scheduled to run at 23:00 daily, but one of the tasks is
+        required to run at 01:00 next day, using ``TimeSensor`` will return
+        ``True`` immediately because 23:00 > 01:00. Instead, we can do this:
+
+        .. code-block:: python
+
+            DateTimeSensor(
+                task_id='wait_for_0100',
+                target_time='{{ next_execution_date.tomorrow().replace(hour=1) }}',
+            )
+
+    :param target_time: datetime after which the job succeeds. (templated)
+    :type target_time: str or datetime.datetime
+    """
+
+    template_fields = ("target_time",)
+
+    @apply_defaults
+    def __init__(
+        self, target_time, *args, **kwargs
+    ):
+        super(DateTimeSensor, self).__init__(*args, **kwargs)
+        if isinstance(target_time, datetime.datetime):
+            self.target_time = target_time.isoformat()
+        elif isinstance(target_time, str):
+            self.target_time = target_time
+        else:
+            raise TypeError(
+                "Expected str or datetime.datetime type for target_time. Got {}".format(
+                    type(target_time)
+                )
+            )
+
+    def poke(self, context):
+        self.log.info("Checking if the time (%s) has come", self.target_time)
+        return timezone.utcnow() > timezone.parse(self.target_time)
diff --git a/tests/sensors/test_date_time_sensor.py b/tests/sensors/test_date_time_sensor.py
new file mode 100644
index 0000000..b8b81d1
--- /dev/null
+++ b/tests/sensors/test_date_time_sensor.py
@@ -0,0 +1,72 @@
+#
+# 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.
+import pytest
+from mock import patch
+from parameterized import parameterized
+
+from airflow.models.dag import DAG
+from airflow.sensors.date_time_sensor import DateTimeSensor
+from airflow.utils import timezone
+
+DEFAULT_DATE = timezone.datetime(2015, 1, 1)
+
+
+class TestDateTimeSensor:
+    @classmethod
+    def setup_class(cls):
+        args = {"owner": "airflow", "start_date": DEFAULT_DATE}
+        cls.dag = DAG("test_dag", default_args=args)
+
+    @parameterized.expand(
+        [
+            (
+                "valid_datetime",
+                timezone.datetime(2020, 7, 6, 13, tzinfo=timezone.utc),
+                "2020-07-06T13:00:00+00:00",
+            ),
+            ("valid_str", "20200706T210000+8", "20200706T210000+8"),
+        ]
+    )
+    def test_valid_input(self, task_id, target_time, expected):
+        op = DateTimeSensor(task_id=task_id, target_time=target_time, dag=self.dag,)
+        assert op.target_time == expected
+
+    def test_invalid_input(self):
+        with pytest.raises(TypeError):
+            DateTimeSensor(
+                task_id="test", target_time=timezone.utcnow().time(), dag=self.dag,
+            )
+
+    @parameterized.expand(
+        [
+            (
+                "poke_datetime",
+                timezone.datetime(2020, 1, 1, 22, 59, tzinfo=timezone.utc),
+                True,
+            ),
+            ("poke_str_extended", "2020-01-01T23:00:00.001+00:00", False),
+            ("poke_str_basic_with_tz", "20200102T065959+8", True),
+        ]
+    )
+    @patch(
+        "airflow.sensors.date_time_sensor.timezone.utcnow",
+        return_value=timezone.datetime(2020, 1, 1, 23, 0, tzinfo=timezone.utc),
+    )
+    def test_poke(self, task_id, target_time, expected, mock_utcnow):
+        op = DateTimeSensor(task_id=task_id, target_time=target_time, dag=self.dag)
+        assert op.poke(None) == expected


[airflow] 02/04: Updated link to official documentation (#9629)

Posted by ka...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit e55f9e115a874c95c3acc352f75868b891f1f3ad
Author: Aviral Agrawal <av...@users.noreply.github.com>
AuthorDate: Thu Jul 2 19:53:27 2020 +0530

    Updated link to official documentation (#9629)
    
    The link to official documentation should point to the documentation page instead of the home page.
    
    (cherry picked from commit 37ca8ad6388e1a8db6403c4a811f971aa9673b41)
---
 docs/project.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/project.rst b/docs/project.rst
index f94eaf1..5b1df44 100644
--- a/docs/project.rst
+++ b/docs/project.rst
@@ -76,7 +76,7 @@ Contributor page:
 Resources & links
 -----------------
 
-* `Airflow's official documentation <http://airflow.apache.org/>`_
+* `Airflow's official documentation <http://airflow.apache.org/docs/>`_
 * Mailing lists:
 
   * Developer's mailing list: dev-subscribe@airflow.apache.org