无法在气流中部署DAG

时间:2020-08-11 14:56:14

标签: airflow google-cloud-dataproc

我无法在气流中部署DAG。不断给出相同的错误。 在8080端口上运行,并且调度程序也处于打开状态。

Running %s on host %s <TaskInstance: bworkflow_dag.bworkflow_template 2020-08-11T00:00:00+00:00 [failed]> airflow-instance-test.c.cc-data-sandbox.internal
[2020-08-11 14:46:29,030] {__init__.py:50} INFO - Using executor SequentialExecutor
[2020-08-11 14:46:29,031] {dagbag.py:396} INFO - Filling up the DagBag from /home/kshitij/airflow/dags
/home/kshitij/.local/lib/python3.5/site-packages/airflow/models/dag.py:1342: PendingDeprecationWarning: The requested task could not be added to the DAG because a task with task_id create_tag_template_field_result is already in the DAG. Starting in Airflow 2.0, trying to overwrite a task will raise an exception.
  category=PendingDeprecationWarning)
Running %s on host %s <TaskInstance: bworkflow_dag.bworkflow_template 2020-08-11T00:00:00+00:00 [failed]> airflow-instance-test.c.cc-data-sandbox.internal

我使用正确的路径,即~/airflow/dags

找到代码段:

from builtins import range
from datetime import timedelta
from airflow.models import DAG
from airflow.utils.dates import days_ago
from airflow.contrib.operators.dataproc_operator import DataprocWorkflowTemplateInstantiateOperator

args = {
    'owner': 'Airflow',
    'start_date': days_ago(2),
}

dag = DAG(
    dag_id='workflow_dag',
    default_args=args,
    schedule_interval=None,
    dagrun_timeout=timedelta(days=1),
)

workflow_template = DataprocWorkflowTemplateInstantiateOperator(
    template_id="workflow_rds",
    project_id="<project name>",
    task_id="workflow_template",
    dag=dag)


workflow_template


if __name__ == "__main__":
    dag.cli()

这是一个单任务DAG。

让我知道我要去哪里错了。

1 个答案:

答案 0 :(得分:2)

如评论所讨论,以下行不是必需的,需要删除

...
workflow_template


if __name__ == "__main__":
    dag.cli()

一对一地带走他们

  • workflow_template:这什么都不做;只是引用一个包含task的变量(将其删除只是清除)
  • if __name__ == "__main__"::仅在文件为executed as a main program时才执行某些代码。 DAG文件中不需要
  • dag.cli():我相信这是铜杯。我以前没有使用过这种方法,但是docstring说了Exposes a CLI specific to this DAG,这在解析dag-definition文件(实际上是webserver)的过程中造成了问题