-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
dataproc_workflow_template_instantiate_operator_tutorial.py
62 lines (52 loc) · 2.09 KB
/
dataproc_workflow_template_instantiate_operator_tutorial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# [START composer_dataproc_workflow_instantiate_operator_tutorial]
"""Example Airflow DAG that kicks off a Cloud Dataproc Template that runs a
Spark Pi Job.
This DAG relies on an Airflow variable
https://airflow.apache.org/docs/apache-airflow/stable/concepts/variables.html
* project_id - Google Cloud Project ID to use for the Cloud Dataproc Template.
"""
import datetime
from airflow import models
from airflow.providers.google.cloud.operators.dataproc import (
DataprocInstantiateWorkflowTemplateOperator,
)
from airflow.utils.dates import days_ago
project_id = "{{var.value.project_id}}"
default_args = {
# Tell airflow to start one day ago, so that it runs as soon as you upload it
"start_date": days_ago(1),
"project_id": project_id,
}
# Define a DAG (directed acyclic graph) of tasks.
# Any task you create within the context manager is automatically added to the
# DAG object.
with models.DAG(
# The id you will see in the DAG airflow page
"dataproc_workflow_dag",
default_args=default_args,
# The interval with which to schedule the DAG
schedule_interval=datetime.timedelta(days=1), # Override to match your needs
) as dag:
start_template_job = DataprocInstantiateWorkflowTemplateOperator(
# The task id of your job
task_id="dataproc_workflow_dag",
# The template id of your workflow
template_id="sparkpi",
project_id=project_id,
# The region for the template
region="us-central1",
)
# [END composer_dataproc_workflow_instantiate_operator_tutorial]