Skip to content

Commit 959afa9

Browse files
authored
Composer: add simple workflow example. Use 1.10beta instead of git. (#1469)
The `composer_simple` sample is intended to demonstrate the concepts of constructing Apache Airflow DAGs rather than any specific set of operators. By using the 1.10beta instead of git for the dependency, we have a stabler package than building on master. Also, this will be easier for Travis to cache.
1 parent a4de1a3 commit 959afa9

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

composer/workflows/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
git+https://github.com/apache/incubator-airflow.git#egg=project[gcp_api]
1+
https://dist.apache.org/repos/dist/dev/incubator/airflow/1.10.0beta1/apache-airflow-1.10.0b1+incubating.tar.gz#egg=apache-airflow[gcp_api]

composer/workflows/simple.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""An example DAG demonstrating simple Apache Airflow operators."""
16+
17+
# [START composer_simple]
18+
from __future__ import print_function
19+
20+
import datetime
21+
22+
from airflow import models
23+
from airflow.operators import bash_operator
24+
from airflow.operators import python_operator
25+
26+
27+
default_dag_args = {
28+
# The start_date describes when a DAG is valid / can be run. Set this to a
29+
# fixed point in time rather than dynamically, since it is evaluated every
30+
# time a DAG is parsed. See:
31+
# https://airflow.apache.org/faq.html#what-s-the-deal-with-start-date
32+
'start_date': datetime.datetime(2018, 1, 1),
33+
}
34+
35+
# Define a DAG (directed acyclic graph) of tasks.
36+
# Any task you create within the context manager is automatically added to the
37+
# DAG object.
38+
with models.DAG(
39+
'simple_greeting',
40+
default_args=default_dag_args) as dag:
41+
def greeting():
42+
print('Hello World!')
43+
44+
# An instance of an operator is called a task. In this case, the
45+
# hello_python task calls the "greeting" Python function.
46+
hello_python = python_operator.PythonOperator(
47+
task_id='hello',
48+
python_callable=greeting)
49+
50+
# Likewise, the goodbye_bash task calls a Bash script.
51+
goodbye_bash = bash_operator.BashOperator(
52+
task_id='bye',
53+
bash_command='echo Goodbye.')
54+
55+
# Define the order in which the tasks complete by using the >> and <<
56+
# operators. In this example, hello_python executes before goodbye_bash.
57+
hello_python >> goodbye_bash
58+
# [END composer_simple]

composer/workflows/simple_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def test_dag_import():
17+
"""Test that the DAG file can be successfully imported.
18+
19+
This tests that the DAG can be parsed, but does not run it in an Airflow
20+
environment. This is a recommended sanity check by the official Airflow
21+
docs: https://airflow.incubator.apache.org/tutorial.html#testing
22+
"""
23+
from . import simple # noqa

0 commit comments

Comments
 (0)