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 2021/04/10 19:14:04 UTC

[airflow] branch master updated: Add picture and examples for Edge Labels (#15310)

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

kaxilnaik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new c8f0abd  Add picture and examples for Edge Labels (#15310)
c8f0abd is described below

commit c8f0abdc1672b9b951f522c7a89d9ebf4cc40032
Author: Andrew Godwin <an...@astronomer.io>
AuthorDate: Sat Apr 10 13:13:40 2021 -0600

    Add picture and examples for Edge Labels (#15310)
    
    This builds on the main feature landing in 19b74fd
---
 airflow/example_dags/example_branch_labels.py   |  40 ++++++++++++++++++++++++
 airflow/example_dags/example_branch_operator.py |   4 ++-
 docs/apache-airflow/concepts.rst                |   5 +++
 docs/apache-airflow/img/edge_label_example.png  | Bin 0 -> 24592 bytes
 4 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/airflow/example_dags/example_branch_labels.py b/airflow/example_dags/example_branch_labels.py
new file mode 100644
index 0000000..4f1cb25
--- /dev/null
+++ b/airflow/example_dags/example_branch_labels.py
@@ -0,0 +1,40 @@
+#
+# 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 labels with different branches.
+"""
+
+from airflow import DAG
+from airflow.operators.dummy import DummyOperator
+from airflow.utils.dates import days_ago
+from airflow.utils.edgemodifier import Label
+
+with DAG("example_branch_labels", schedule_interval="@daily", start_date=days_ago(2)) as dag:
+
+    ingest = DummyOperator(task_id="ingest")
+    analyse = DummyOperator(task_id="analyze")
+    check = DummyOperator(task_id="check_integrity")
+    describe = DummyOperator(task_id="describe_integrity")
+    error = DummyOperator(task_id="email_error")
+    save = DummyOperator(task_id="save")
+    report = DummyOperator(task_id="report")
+
+    ingest >> analyse >> check
+    check >> Label("No errors") >> save >> report  # pylint: disable=expression-not-assigned
+    check >> Label("Errors found") >> describe >> error >> report  # pylint: disable=expression-not-assigned
diff --git a/airflow/example_dags/example_branch_operator.py b/airflow/example_dags/example_branch_operator.py
index 7c5e166..6c1fb8f 100644
--- a/airflow/example_dags/example_branch_operator.py
+++ b/airflow/example_dags/example_branch_operator.py
@@ -24,6 +24,7 @@ from airflow import DAG
 from airflow.operators.dummy import DummyOperator
 from airflow.operators.python import BranchPythonOperator
 from airflow.utils.dates import days_ago
+from airflow.utils.edgemodifier import Label
 
 args = {
     'owner': 'airflow',
@@ -63,4 +64,5 @@ with DAG(
             task_id='follow_' + option,
         )
 
-        branching >> t >> dummy_follow >> join
+        # Label is optional here, but it can help identify more complex branches
+        branching >> Label(option) >> t >> dummy_follow >> join  # pylint: disable=expression-not-assigned
diff --git a/docs/apache-airflow/concepts.rst b/docs/apache-airflow/concepts.rst
index 25b3fb9..4712007 100644
--- a/docs/apache-airflow/concepts.rst
+++ b/docs/apache-airflow/concepts.rst
@@ -1159,6 +1159,11 @@ Or, you can use them directly inline with the ``>>`` and ``<<`` operators:
     from airflow.utils.edgemodifier import Label
     my_task >> Label("When empty") >> other_task
 
+Here's an example DAG which illustrates labeling different branches:
+
+.. image:: img/edge_label_example.png
+
+.. exampleinclude:: /../../airflow/example_dags/example_branch_labels.py
 
 SLAs
 ====
diff --git a/docs/apache-airflow/img/edge_label_example.png b/docs/apache-airflow/img/edge_label_example.png
new file mode 100755
index 0000000..6df0afc
Binary files /dev/null and b/docs/apache-airflow/img/edge_label_example.png differ