Created
January 29, 2019 21:17
-
-
Save wanghq/ee15d2b4ac7597332981689de8940e42 to your computer and use it in GitHub Desktop.
DAG demonstrating task dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Code that goes along with the Airflow tutorial located at: | |
https://github.com/apache/incubator-airflow/blob/master/airflow/example_dags/tutorial.py | |
""" | |
from airflow import DAG | |
from airflow.operators.bash_operator import BashOperator | |
from datetime import datetime, timedelta | |
default_args = { | |
'owner': 'airflow', | |
'depends_on_past': False, | |
'start_date': datetime(2015, 6, 1), | |
'email': ['a@gmail.com'], | |
'email_on_failure': False, | |
'email_on_retry': False, | |
'retries': 1, | |
'retry_delay': timedelta(minutes=5), | |
# 'queue': 'bash_queue', | |
# 'pool': 'backfill', | |
# 'priority_weight': 10, | |
# 'end_date': datetime(2016, 1, 1), | |
} | |
dag = DAG('complex_dag', default_args=default_args, schedule_interval=timedelta(days=1)) | |
t0 = BashOperator( | |
task_id='t0', | |
bash_command='date', | |
dag=dag) | |
t1 = BashOperator( | |
task_id='t1', | |
bash_command='date', | |
dag=dag) | |
t2 = BashOperator( | |
task_id='t2', | |
bash_command='sleep 5', | |
retries=3, | |
dag=dag) | |
t3 = BashOperator( | |
task_id='t3', | |
bash_command='sleep 5', | |
retries=3, | |
dag=dag) | |
t4 = BashOperator( | |
task_id='t4', | |
bash_command='date', | |
dag=dag) | |
t5 = BashOperator( | |
task_id='t5', | |
bash_command='date', | |
dag=dag) | |
t6 = BashOperator( | |
task_id='t6', | |
bash_command='date', | |
dag=dag) | |
t7 = BashOperator( | |
task_id='t7', | |
bash_command='date', | |
dag=dag) | |
t1.set_upstream(t0) | |
t2.set_upstream(t0) | |
t3.set_upstream(t1) | |
t4.set_upstream(t1) | |
t5.set_upstream(t2) | |
t2.set_downstream(t4) | |
t3.set_downstream(t6) | |
t4.set_downstream(t6) | |
t5.set_downstream(t7) | |
t6.set_downstream(t7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment