gpt4 book ai didi

Airflow DAG Loop - 如何使每次迭代顺序而不是并行

转载 作者:行者123 更新时间:2023-12-03 23:51:59 26 4
gpt4 key购买 nike

我有一个 Apache Airflow DAG,如下所示:

DAG_NAME='my_dag'
sections = ["0", "1", "2", "3"]

with DAG(DAG_NAME, default_args=default_args, schedule_interval=None) as dag:

for s in sections:
a = DummyOperator(task_id=f"section_{s}_start")
b = SubDagOperator(task_id=f"init_{s}_subdag",subdag=init_section(DAG_NAME,f"init_{s}_subdag", default_args))
c = SubDagOperator(task_id=f"process_{s}_subdag", subdag=process_section(DAG_NAME,f"process_{s}_subdag", default_args))
d = SubDagOperator(task_id=f"update_{s}_subdag", subdag=update_section(DAG_NAME,f"update_{s}_subdag", default_args))
e = DummyOperator(task_id=f"section_{s}_end")
a>>b>>c>>d>>e
这段代码像这样呈现我的任务 enter image description here
enter image description here
我怎样才能使任务序列是:
section_0_start>>init_0_subdag>>process_0_subdag>>update_0_subdag>>section_0_end
section_0_end>>section_1_start
section_1_start>>init_1_subdag>>process_1_subdag>>update_1_subdag>>section_1_end
.....
依此类推,从第 0 部分到第 3 部分任务结束
谢谢

最佳答案

像这样修改for循环:

    previous_e = None
for s in sections:
a = ...
...
e = ...
if previous_e:
previous_e >> a
a>>b>>c>>d>>e
previous_e = e

关于Airflow DAG Loop - 如何使每次迭代顺序而不是并行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56292433/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com