Airflow 气流:使用分支跳过任务
在我的DAG中,想要跳过一个依赖于标志的任务(oracle\u merge\u hist\u orig) 我的逻辑是: 当oracle\u branch=True时,执行[merge\u op,update\u table\u op,table\u count\u op] 当oracle\u branch=False时,执行[update\u table\u op,table\u count\u op] 我尝试使用BranchPythonOperator,如下所示:Airflow 气流:使用分支跳过任务,airflow,Airflow,在我的DAG中,想要跳过一个依赖于标志的任务(oracle\u merge\u hist\u orig) 我的逻辑是: 当oracle\u branch=True时,执行[merge\u op,update\u table\u op,table\u count\u op] 当oracle\u branch=False时,执行[update\u table\u op,table\u count\u op] 我尝试使用BranchPythonOperator,如下所示: args = { '
args = {
'owner': 'Airflow',
'start_date': airflow.utils.dates.days_ago(2),
}
oracle_branch = True
def branch_func():
if oracle_branch:
return "oracle_branch"
else:
return "normal_branch"
dag = DAG(
dag_id='example_branch_operator',
default_args=args,
schedule_interval="@daily",
)
branching_op = BranchPythonOperator(
task_id='branch_shall_run_oracle_merge_original_hist',
python_callable=branch_func,
dag= dag)
oracle_branch = DummyOperator(
task_id='oracle_branch',
dag=dag)
normal_branch = DummyOperator(
task_id='normal_branch',
dag=dag)
merge_op = DummyOperator(
task_id='oracle_merge_hist_orig',
dag=dag,
)
update_table_op = DummyOperator(
task_id='update_table_job',
dag=dag,
)
table_count_op = DummyOperator(
task_id='table_count',
dag=dag,
)
branching_op >> [oracle_branch,normal_branch]
normal_branch >> update_table_op >> table_count_op
oracle_branch >> merge_op >> update_table_op >> table_count_op
但是,它不会跳过任务,而是跳过整个路径
如何解决这个问题,使我只跳过“racle\u merge\u hist\u orig”任务
当oracle\u branch=False时
当oracle\u branch=True时
每个任务都有一个
触发规则
,默认设置为all\u success
。我们可以将其覆盖为列出的不同值
在DAG中,update\u table\u作业
任务有两个上游任务。因为它的一个上游任务处于skipped
状态,所以它也进入了skipped
状态。我们可以通过将trigger\u rule
的默认值重写为one\u success
来避免这种情况,如下所示
update\u table\u op=dummy运算符(
任务\u id='update\u table\u job',
触发规则“一次成功”,
dag=dag
)
注意:我在Airflow 1.10.4版本上进行了测试。您使用的是哪个Airflow版本?。我在Airflow 1.8中测试了相同的代码,它工作正常。@SaiKiranNeelakantam我使用版本1.10.3I能够重现您在Airflow 1.10.4中的错误,并在下面发布了一个解决问题的答案。