|
| 1 | +""" |
| 2 | +Code that goes along with the Airflow located at: |
| 3 | +http://airflow.readthedocs.org/en/latest/tutorial.html |
| 4 | +""" |
| 5 | +from airflow import DAG |
| 6 | +from airflow.operators.bash_operator import BashOperator |
| 7 | +from datetime import datetime, timedelta |
| 8 | + |
| 9 | + |
| 10 | +default_args = { |
| 11 | + "owner": "airflow", |
| 12 | + "depends_on_past": False, |
| 13 | + "start_date": datetime(2015, 6, 1), |
| 14 | + |
| 15 | + "email_on_failure": False, |
| 16 | + "email_on_retry": False, |
| 17 | + "retries": 1, |
| 18 | + "retry_delay": timedelta(minutes=5), |
| 19 | + # 'queue': 'bash_queue', |
| 20 | + # 'pool': 'backfill', |
| 21 | + # 'priority_weight': 10, |
| 22 | + # 'end_date': datetime(2016, 1, 1), |
| 23 | +} |
| 24 | + |
| 25 | +dag = DAG("tutorial", default_args=default_args, schedule_interval=timedelta(1)) |
| 26 | + |
| 27 | +# t1, t2 and t3 are examples of tasks created by instantiating operators |
| 28 | +t1 = BashOperator(task_id="print_date", bash_command="date", dag=dag) |
| 29 | + |
| 30 | +t2 = BashOperator(task_id="sleep", bash_command="sleep 5", retries=3, dag=dag) |
| 31 | + |
| 32 | +templated_command = """ |
| 33 | + {% for i in range(5) %} |
| 34 | + echo "{{ ds }}" |
| 35 | + echo "{{ macros.ds_add(ds, 7)}}" |
| 36 | + echo "{{ params.my_param }}" |
| 37 | + {% endfor %} |
| 38 | +""" |
| 39 | + |
| 40 | +t3 = BashOperator( |
| 41 | + task_id="templated", |
| 42 | + bash_command=templated_command, |
| 43 | + params={"my_param": "Parameter I passed in"}, |
| 44 | + dag=dag, |
| 45 | +) |
| 46 | + |
| 47 | +t2.set_upstream(t1) |
| 48 | +t3.set_upstream(t1) |
0 commit comments