Created
March 10, 2018 18:59
-
-
Save joaoferrao/38a3444a3166e6951cedf7b58591262c to your computer and use it in GitHub Desktop.
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
# from https://github.com/apache/incubator-airflow/blob/master/airflow/example_dags/tutorial.py | |
# -*- coding: utf-8 -*- | |
""" | |
### Tutorial Documentation | |
Documentation that goes along with the Airflow tutorial located | |
[here](https://airflow.incubator.apache.org/tutorial.html) | |
""" | |
import airflow | |
from airflow import DAG | |
from airflow.operators.bash_operator import BashOperator | |
from datetime import timedelta | |
# these args will get passed on to each operator | |
# you can override them on a per-task basis during operator initialization | |
default_args = { | |
'owner': 'airflow', | |
'depends_on_past': False, | |
'start_date': airflow.utils.dates.days_ago(2), | |
'email': ['[email protected]'], | |
'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), | |
# 'wait_for_downstream': False, | |
# 'dag': dag, | |
# 'adhoc':False, | |
# 'sla': timedelta(hours=2), | |
# 'execution_timeout': timedelta(seconds=300), | |
# 'on_failure_callback': some_function, | |
# 'on_success_callback': some_other_function, | |
# 'on_retry_callback': another_function, | |
# 'trigger_rule': u'all_success' | |
} | |
dag = DAG( | |
'tutorial', | |
default_args=default_args, | |
description='A simple tutorial DAG', | |
schedule_interval=timedelta(days=1)) | |
# t1, t2 and t3 are examples of tasks created by instantiating operators | |
t1 = BashOperator( | |
task_id='print_date', | |
bash_command='date', | |
dag=dag) | |
t1.doc_md = """\ | |
#### Task Documentation | |
You can document your task using the attributes `doc_md` (markdown), | |
`doc` (plain text), `doc_rst`, `doc_json`, `doc_yaml` which gets | |
rendered in the UI's Task Instance Details page. | |
 | |
""" | |
dag.doc_md = __doc__ | |
t2 = BashOperator( | |
task_id='sleep', | |
depends_on_past=False, | |
bash_command='sleep 5', | |
dag=dag) | |
templated_command = """ | |
{% for i in range(5) %} | |
echo "{{ ds }}" | |
echo "{{ macros.ds_add(ds, 7)}}" | |
echo "{{ params.my_param }}" | |
{% endfor %} | |
""" | |
t3 = BashOperator( | |
task_id='templated', | |
depends_on_past=False, | |
bash_command=templated_command, | |
params={'my_param': 'Parameter I passed in'}, | |
dag=dag) | |
t2.set_upstream(t1) | |
t3.set_upstream(t1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment