|
16 | 16 | # KIND, either express or implied. See the License for the |
17 | 17 | # specific language governing permissions and limitations |
18 | 18 | # under the License. |
19 | | - |
20 | 19 | """ |
21 | 20 | Example Airflow DAG that shows the complex DAG structure. |
22 | 21 | """ |
| 22 | +import sys |
23 | 23 |
|
24 | 24 | from airflow import models |
25 | | -from airflow.models.baseoperator import chain |
26 | 25 | from airflow.operators.bash_operator import BashOperator |
27 | 26 | from airflow.operators.python_operator import PythonOperator |
28 | 27 | from airflow.utils.dates import days_ago |
| 28 | +from airflow.utils.helpers import chain |
29 | 29 |
|
30 | 30 | default_args = {"start_date": days_ago(1)} |
31 | 31 |
|
32 | | -with models.DAG("example_complex", default_args=default_args, schedule_interval=None) as dag: |
| 32 | +with models.DAG("complex", |
| 33 | + default_args=default_args, |
| 34 | + schedule_interval=None) as dag: |
33 | 35 |
|
34 | 36 | # Create |
35 | | - create_entry_group = BashOperator(task_id="create_entry_group", bash_command="echo create_entry_group") |
| 37 | + create_entry_group = BashOperator(task_id="create_entry_group", |
| 38 | + bash_command="echo create_entry_group") |
36 | 39 |
|
37 | 40 | create_entry_group_result = BashOperator( |
38 | | - task_id="create_entry_group_result", bash_command="echo create_entry_group_result" |
39 | | - ) |
| 41 | + task_id="create_entry_group_result", |
| 42 | + bash_command="echo create_entry_group_result") |
40 | 43 |
|
41 | 44 | create_entry_group_result2 = BashOperator( |
42 | | - task_id="create_entry_group_result2", bash_command="echo create_entry_group_result2" |
43 | | - ) |
| 45 | + task_id="create_entry_group_result2", |
| 46 | + bash_command="echo create_entry_group_result2") |
44 | 47 |
|
45 | | - create_entry_gcs = BashOperator(task_id="create_entry_gcs", bash_command="echo create_entry_gcs") |
| 48 | + create_entry_gcs = BashOperator(task_id="create_entry_gcs", |
| 49 | + bash_command="echo create_entry_gcs") |
46 | 50 |
|
47 | 51 | create_entry_gcs_result = BashOperator( |
48 | | - task_id="create_entry_gcs_result", bash_command="echo create_entry_gcs_result" |
49 | | - ) |
| 52 | + task_id="create_entry_gcs_result", |
| 53 | + bash_command="echo create_entry_gcs_result") |
50 | 54 |
|
51 | 55 | create_entry_gcs_result2 = BashOperator( |
52 | | - task_id="create_entry_gcs_result2", bash_command="echo create_entry_gcs_result2" |
53 | | - ) |
| 56 | + task_id="create_entry_gcs_result2", |
| 57 | + bash_command="echo create_entry_gcs_result2") |
54 | 58 |
|
55 | | - create_tag = BashOperator(task_id="create_tag", bash_command="echo create_tag") |
| 59 | + create_tag = BashOperator(task_id="create_tag", |
| 60 | + bash_command="echo create_tag") |
56 | 61 |
|
57 | | - create_tag_result = BashOperator(task_id="create_tag_result", bash_command="echo create_tag_result") |
| 62 | + create_tag_result = BashOperator(task_id="create_tag_result", |
| 63 | + bash_command="echo create_tag_result") |
58 | 64 |
|
59 | | - create_tag_result2 = BashOperator(task_id="create_tag_result2", bash_command="echo create_tag_result2") |
| 65 | + create_tag_result2 = BashOperator(task_id="create_tag_result2", |
| 66 | + bash_command="echo create_tag_result2") |
60 | 67 |
|
61 | | - create_tag_template = BashOperator(task_id="create_tag_template", bash_command="echo create_tag_template") |
| 68 | + create_tag_template = BashOperator(task_id="create_tag_template", |
| 69 | + bash_command="echo create_tag_template") |
62 | 70 |
|
63 | 71 | create_tag_template_result = BashOperator( |
64 | | - task_id="create_tag_template_result", bash_command="echo create_tag_template_result" |
65 | | - ) |
| 72 | + task_id="create_tag_template_result", |
| 73 | + bash_command="echo create_tag_template_result") |
66 | 74 |
|
67 | 75 | create_tag_template_result2 = BashOperator( |
68 | | - task_id="create_tag_template_result2", bash_command="echo create_tag_template_result2" |
69 | | - ) |
| 76 | + task_id="create_tag_template_result2", |
| 77 | + bash_command="echo create_tag_template_result2") |
70 | 78 |
|
71 | 79 | create_tag_template_field = BashOperator( |
72 | | - task_id="create_tag_template_field", bash_command="echo create_tag_template_field" |
73 | | - ) |
| 80 | + task_id="create_tag_template_field", |
| 81 | + bash_command="echo create_tag_template_field") |
74 | 82 |
|
75 | 83 | create_tag_template_field_result = BashOperator( |
76 | | - task_id="create_tag_template_field_result", bash_command="echo create_tag_template_field_result" |
77 | | - ) |
| 84 | + task_id="create_tag_template_field_result", |
| 85 | + bash_command="echo create_tag_template_field_result") |
78 | 86 |
|
79 | 87 | create_tag_template_field_result2 = BashOperator( |
80 | | - task_id="create_tag_template_field_result", bash_command="echo create_tag_template_field_result" |
81 | | - ) |
| 88 | + task_id="create_tag_template_field_result", |
| 89 | + bash_command="echo create_tag_template_field_result") |
82 | 90 |
|
83 | 91 | # Delete |
84 | | - delete_entry = BashOperator(task_id="delete_entry", bash_command="echo delete_entry") |
| 92 | + delete_entry = BashOperator(task_id="delete_entry", |
| 93 | + bash_command="echo delete_entry") |
85 | 94 | create_entry_gcs >> delete_entry |
86 | 95 |
|
87 | | - delete_entry_group = BashOperator(task_id="delete_entry_group", bash_command="echo delete_entry_group") |
| 96 | + delete_entry_group = BashOperator(task_id="delete_entry_group", |
| 97 | + bash_command="echo delete_entry_group") |
88 | 98 | create_entry_group >> delete_entry_group |
89 | 99 |
|
90 | | - delete_tag = BashOperator(task_id="delete_tag", bash_command="echo delete_tag") |
| 100 | + delete_tag = BashOperator(task_id="delete_tag", |
| 101 | + bash_command="echo delete_tag") |
91 | 102 | create_tag >> delete_tag |
92 | 103 |
|
93 | 104 | delete_tag_template_field = BashOperator( |
94 | | - task_id="delete_tag_template_field", bash_command="echo delete_tag_template_field" |
95 | | - ) |
| 105 | + task_id="delete_tag_template_field", |
| 106 | + bash_command="echo delete_tag_template_field") |
96 | 107 |
|
97 | | - delete_tag_template = BashOperator(task_id="delete_tag_template", bash_command="echo delete_tag_template") |
| 108 | + delete_tag_template = BashOperator(task_id="delete_tag_template", |
| 109 | + bash_command="echo delete_tag_template") |
98 | 110 |
|
99 | 111 | # Get |
100 | | - get_entry_group = BashOperator(task_id="get_entry_group", bash_command="echo get_entry_group") |
| 112 | + get_entry_group = BashOperator(task_id="get_entry_group", |
| 113 | + bash_command="echo get_entry_group") |
101 | 114 |
|
102 | 115 | get_entry_group_result = BashOperator( |
103 | | - task_id="get_entry_group_result", bash_command="echo get_entry_group_result" |
104 | | - ) |
| 116 | + task_id="get_entry_group_result", |
| 117 | + bash_command="echo get_entry_group_result") |
105 | 118 |
|
106 | 119 | get_entry = BashOperator(task_id="get_entry", bash_command="echo get_entry") |
107 | 120 |
|
108 | | - get_entry_result = BashOperator(task_id="get_entry_result", bash_command="echo get_entry_result") |
| 121 | + get_entry_result = BashOperator(task_id="get_entry_result", |
| 122 | + bash_command="echo get_entry_result") |
109 | 123 |
|
110 | | - get_tag_template = BashOperator(task_id="get_tag_template", bash_command="echo get_tag_template") |
| 124 | + get_tag_template = BashOperator(task_id="get_tag_template", |
| 125 | + bash_command="echo get_tag_template") |
111 | 126 |
|
112 | 127 | get_tag_template_result = BashOperator( |
113 | | - task_id="get_tag_template_result", bash_command="echo get_tag_template_result" |
114 | | - ) |
| 128 | + task_id="get_tag_template_result", |
| 129 | + bash_command="echo get_tag_template_result") |
115 | 130 |
|
116 | 131 | # List |
117 | 132 | list_tags = BashOperator(task_id="list_tags", bash_command="echo list_tags") |
118 | 133 |
|
119 | | - list_tags_result = BashOperator(task_id="list_tags_result", bash_command="echo list_tags_result") |
| 134 | + list_tags_result = BashOperator(task_id="list_tags_result", |
| 135 | + bash_command="echo list_tags_result") |
120 | 136 |
|
121 | 137 | # Lookup |
122 | | - lookup_entry = BashOperator(task_id="lookup_entry", bash_command="echo lookup_entry") |
| 138 | + lookup_entry = BashOperator(task_id="lookup_entry", |
| 139 | + bash_command="echo lookup_entry") |
123 | 140 |
|
124 | | - lookup_entry_result = BashOperator(task_id="lookup_entry_result", bash_command="echo lookup_entry_result") |
| 141 | + lookup_entry_result = BashOperator(task_id="lookup_entry_result", |
| 142 | + bash_command="echo lookup_entry_result") |
125 | 143 |
|
126 | 144 | # Rename |
127 | 145 | rename_tag_template_field = BashOperator( |
128 | | - task_id="rename_tag_template_field", bash_command="echo rename_tag_template_field" |
129 | | - ) |
| 146 | + task_id="rename_tag_template_field", |
| 147 | + bash_command="echo rename_tag_template_field") |
130 | 148 |
|
131 | 149 | # Search |
132 | | - search_catalog = PythonOperator(task_id="search_catalog", python_callable=lambda: print("search_catalog")) |
| 150 | + search_catalog = PythonOperator( |
| 151 | + task_id="search_catalog", |
| 152 | + python_callable=lambda _: sys.stdout.write("search_catalog\n")) |
133 | 153 |
|
134 | 154 | search_catalog_result = BashOperator( |
135 | | - task_id="search_catalog_result", bash_command="echo search_catalog_result" |
136 | | - ) |
| 155 | + task_id="search_catalog_result", |
| 156 | + bash_command="echo search_catalog_result") |
137 | 157 |
|
138 | 158 | # Update |
139 | | - update_entry = BashOperator(task_id="update_entry", bash_command="echo update_entry") |
| 159 | + update_entry = BashOperator(task_id="update_entry", |
| 160 | + bash_command="echo update_entry") |
140 | 161 |
|
141 | | - update_tag = BashOperator(task_id="update_tag", bash_command="echo update_tag") |
| 162 | + update_tag = BashOperator(task_id="update_tag", |
| 163 | + bash_command="echo update_tag") |
142 | 164 |
|
143 | | - update_tag_template = BashOperator(task_id="update_tag_template", bash_command="echo update_tag_template") |
| 165 | + update_tag_template = BashOperator(task_id="update_tag_template", |
| 166 | + bash_command="echo update_tag_template") |
144 | 167 |
|
145 | 168 | update_tag_template_field = BashOperator( |
146 | | - task_id="update_tag_template_field", bash_command="echo update_tag_template_field" |
147 | | - ) |
| 169 | + task_id="update_tag_template_field", |
| 170 | + bash_command="echo update_tag_template_field") |
148 | 171 |
|
149 | 172 | # Create |
150 | 173 | create_tasks = [ |
|
208 | 231 | create_tag_template_field >> rename_tag_template_field >> delete_tag_template_field |
209 | 232 |
|
210 | 233 | # Search |
211 | | - chain(create_tasks, search_catalog, delete_tasks) |
| 234 | + search_catalog.set_upstream(create_tasks) |
| 235 | + search_catalog.set_downstream(delete_tasks) |
212 | 236 | search_catalog >> search_catalog_result |
213 | 237 |
|
214 | 238 | # Update |
|
0 commit comments