在我的DAG中,我希望根据一个标志跳过一个任务(oracle_merge_hist_orig)。
我的逻辑是:
当oracle_branch=True时,执行[merge_op,update_table_op,table_count_op]
当oracle_branch=False时,执行[update_table_op, table_count_op]
我尝试使用BranchPythonOperator,如下所示:
然而,它跳过的不是任务,而是整个路径。
如何修复此问题,以便我只跳过“racle_merge_hist_orig”任务?
当oracle_branch=False时 当oracle_branch=True时
我的逻辑是:
当oracle_branch=True时,执行[merge_op,update_table_op,table_count_op]
当oracle_branch=False时,执行[update_table_op, table_count_op]
我尝试使用BranchPythonOperator,如下所示:
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_merge_hist_orig”任务?
当oracle_branch=False时 当oracle_branch=True时