1+ # -*- coding: utf-8 -*-
2+ #
3+ # Licensed to the Apache Software Foundation (ASF) under one
4+ # or more contributor license agreements. See the NOTICE file
5+ # distributed with this work for additional information
6+ # regarding copyright ownership. The ASF licenses this file
7+ # to you under the Apache License, Version 2.0 (the
8+ # "License"); you may not use this file except in compliance
9+ # with the License. You may obtain a copy of the License at
10+ #
11+ # http://www.apache.org/licenses/LICENSE-2.0
12+ #
13+ # Unless required by applicable law or agreed to in writing,
14+ # software distributed under the License is distributed on an
15+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+ # KIND, either express or implied. See the License for the
17+ # specific language governing permissions and limitations
18+ # under the License.
19+
20+ """
21+ ### Tutorial Documentation
22+ Documentation that goes along with the Airflow tutorial located
23+ [here](https://airflow.incubator.apache.org/tutorial.html)
24+ """
25+ from datetime import timedelta
26+
27+ import airflow
28+ from airflow import DAG
29+ from airflow .operators .bash_operator import BashOperator
30+
31+ # These args will get passed on to each operator
32+ # You can override them on a per-task basis during operator initialization
33+ default_args = {
34+ 'owner' : 'airflow' ,
35+ 'depends_on_past' : False ,
36+ 'start_date' : airflow .utils .dates .days_ago (2 ),
37+ 'email' : ['airflow@example.com' ],
38+ 'email_on_failure' : False ,
39+ 'email_on_retry' : False ,
40+ 'retries' : 1 ,
41+ 'retry_delay' : timedelta (minutes = 5 ),
42+ # 'queue': 'bash_queue',
43+ # 'pool': 'backfill',
44+ # 'priority_weight': 10,
45+ # 'end_date': datetime(2016, 1, 1),
46+ # 'wait_for_downstream': False,
47+ # 'dag': dag,
48+ # 'adhoc':False,
49+ # 'sla': timedelta(hours=2),
50+ # 'execution_timeout': timedelta(seconds=300),
51+ # 'on_failure_callback': some_function,
52+ # 'on_success_callback': some_other_function,
53+ # 'on_retry_callback': another_function,
54+ # 'trigger_rule': u'all_success'
55+ }
56+
57+ dag = DAG (
58+ 'tutorial' ,
59+ default_args = default_args ,
60+ description = 'A simple tutorial DAG' ,
61+ schedule_interval = timedelta (days = 1 ),
62+ )
63+
64+ # t1, t2 and t3 are examples of tasks created by instantiating operators
65+ t1 = BashOperator (
66+ task_id = 'print_date' ,
67+ bash_command = 'date' ,
68+ dag = dag ,
69+ )
70+
71+ t1 .doc_md = """\
72+ #### Task Documentation
73+ You can document your task using the attributes `doc_md` (markdown),
74+ `doc` (plain text), `doc_rst`, `doc_json`, `doc_yaml` which gets
75+ rendered in the UI's Task Instance Details page.
76+ 
77+ """
78+
79+ dag .doc_md = __doc__
80+
81+ t2 = BashOperator (
82+ task_id = 'sleep' ,
83+ depends_on_past = False ,
84+ bash_command = 'sleep 5' ,
85+ dag = dag ,
86+ )
87+
88+ templated_command = """
89+ {% for i in range(5) %}
90+ echo "{{ ds }}"
91+ echo "{{ macros.ds_add(ds, 7)}}"
92+ echo "{{ params.my_param }}"
93+ {% endfor %}
94+ """
95+
96+ t3 = BashOperator (
97+ task_id = 'templated' ,
98+ depends_on_past = False ,
99+ bash_command = templated_command ,
100+ params = {'my_param' : 'Parameter I passed in' },
101+ dag = dag ,
102+ )
103+
104+ t1 >> [t2 , t3 ]
0 commit comments