8000 Add new composer quickstart code (#2249) · dalequark/python-docs-samples@741b0b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 741b0b7

Browse files
authored
Add new composer quickstart code (GoogleCloudPlatform#2249)
* Add new quickstart code * Modify bash command
1 parent 29e4cd6 commit 741b0b7

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

composer/workflows/quickstart.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2019 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+
# [START composer_quickstart]
16+
import datetime
17+
18+
import airflow
19+
from airflow.operators import bash_operator
20+
21+
YESTERDAY = datetime.datetime.now() - datetime.timedelta(days=1)
22+
23+
default_args = {
24+
'owner': 'Composer Example',
25+
'depends_on_past': False,
26+
'email': [''],
27+
'email_on_failure': False,
28+
'email_on_retry': False,
29+
'retries': 1,
30+
'retry_delay': datetime.timedelta(minutes=5),
31+
'start_date': YESTERDAY,
32+
}
33+
34+
with airflow.DAG(
35+
'composer_sample_dag',
36+
'catchup=False',
37+
default_args=default_args,
38+
schedule_interval=datetime.timedelta(days=1)) as dag:
39+
40+
# Print the dag_run id from the Airflow logs
41+
print_dag_run_conf = bash_operator.BashOperator(
42+
task_id='print_dag_run_conf', bash_command='echo {{ dag_run.id }}')
43+
# [END composer_quickstart]

composer/workflows/quickstart_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2019 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+
from airflow import models
16+
17+
from . import unit_testing
18+
19+
20+
def test_dag_import():
21+
"""Test that the DAG file can be successfully imported.
22+
23+
This tests that the DAG can be parsed, but does not run it in an Airflow
24+
environment. This is a recommended sanity check by the official Airflow
25+
docs: https://airflow.incubator.apache.org/tutorial.html#testing
26+
"""
27+
models.Variable.set('gcs_bucket', 'example_bucket')
28+
models.Variable.set('gcp_project', 'example-project')
29+
models.Variable.set('gce_zone', 'us-central1-f')
30+
from . import quickstart as module
31+
unit_testing.assert_has_valid_dag(module)

0 commit comments

Comments
 (0)
0