我正在使用以下代码:
================================================
from datetime import timedelta, datetime
from airflow import DAG
from airflow.contrib.operators.dataflow_operator import DataflowTemplateOperator
from airflow.operators.dummy_operator import DummyOperator
from airflow.models import Variable
PROJECT = Variable.get('gcp_project')
print("project"+PROJECT)
TEMP_BUCKET = Variable.get('stg_bucket')
TEMPLATE = "gs://*************"
INPUT_FILE = "{\"location1\":\"test:random.Summary\"}"
OUTPUT_FILE = "{\"location1\":\"test:random.TestSummary\"}"
PARAMETERS = {
'inputFile': INPUT_FILE,
'outputFile': OUTPUT_FILE
}
TODAY = datetime.today()
TODAY_STRING = datetime.today().strftime('%Y%m%d')
DEFAULT_DAG_ARGS = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': TODAY,
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
'schedule_interval': '@hourly',
'dataflow_default_options': {
'project': PROJECT,
'region':'us-west1',
'zone': 'us-west1-b',
'tempLocation': TEMP_BUCKET
}
}
dag = DAG(
'Demo-DAG-DataflowTemplate',
default_args=DEFAULT_DAG_ARGS,
dagrun_timeout=timedelta(hours=1)
)
start = DummyOperator(task_id='inicio', dag=dag)
end = DummyOperator(task_id='fim', dag=dag)
t1 = DataflowTemplateOperator(
task_id='dataflow_template_launch',
template=TEMPLATE,
parameters=PARAMETERS,
dag=dag)
start >> t1 >> end
================================================ ================================================== === 但是,在运行DAG时遇到问题。错误提示:
返回“模板参数无效。”
我能够使用普通的python代码运行相同的模板,但是当我使用DataflowTemplateOperator时,它不会执行。有人可以帮我吗?