Airflow BranchPythonOperator不遵循指定的分支

时间:2018-10-23 09:20:00

标签: python airflow

我有一个具有以下结构的AIRFLOW DAG。

Airflow Graph View

所有以“ check *”开头的函数都是BranchPythonOperator,而函数exceptionControl是ExecuteDagRunOperator,它会接收所有错误以进行处理。

这是DAG配置:

checkCloudFunctions = BranchPythonOperator(
    task_id='checkCloudFunctions',
    python_callable=check_cloud_functions,
    provide_context=True,
    dag=dag)

checkSqlTables = BranchPythonOperator(
    task_id='checkSqlTables',
    python_callable=check_sql_tables,
    provide_context=True,
    dag=dag)

checkBigQueryTable = BranchPythonOperator(
    task_id='checkBigQueryTable',
    python_callable=check_big_query_table,
    provide_context=True,
    dag=dag)

labBuilt = DummyOperator(
    task_id='labBuilt',
    dag=dag)

exceptionControl = ExecuteDagRunOperator(
    task_id='exceptionControl',
    execute_dag_id="SYS_exception_control",
    python_callable=mediation.dag_trigger_exception,
    trigger_rule='one_success',
    dag=dag)

# graphs
checkCloudFunctions >> checkSqlTables
checkCloudFunctions >> exceptionControl

checkSqlTables >> checkBigQueryTable
checkSqlTables >> exceptionControl

checkBigQueryTable >> labBuilt
checkBigQueryTable >> exceptionControl

问题是,checkSqlTables应该遵循此规则来进行异常控制,但是它会跳过并且DAG结束。如我们在checkSqlTables日志中所见,该函数返回“ exceptionControl”:

   {base_task_runner.py:98} INFO - {python_operator.py:90} INFO - Done. Returned value was: exceptionControl
   {base_task_runner.py:98} INFO - {python_operator.py:118} INFO - Following branch exceptionControl
   {base_task_runner.py:98} INFO - {python_operator.py:119} INFO - Marking other directly downstream tasks as skipped
   {base_task_runner.py:98} INFO - {python_operator.py:128} INFO - Done.

我还使用了 trigger_rule 属性(one_success,dummy ...),但这似乎不起作用。

如果我删除了第一步,它似乎可以正常工作,所以看来我的dag应该是某种配置问题。

enter image description here

有什么想法为什么函数checkSqlTables不会分支到exceptionControl?

编辑:在new deep reading to the Airflow Documentation中,我注意到,如果某个步骤将某个任务标记为已跳过,则它将永远被跳过,因此我的代码将永远无法与Branching Operators一起使用。

使用分支的解决方案在每个步骤之前都包含一个虚拟步骤。但是我有一些DAG包含十多个步骤,并且该架构将完全混乱。

0 个答案:

没有答案