Airflow 循环中的DAG任务依赖关系
我有一个DAG需要重新编译不同品牌的客户列表。使用两个参数brand和listtype调用脚本 我需要品牌同时运行,但是列表类型依赖于前面的列表类型,但是我不知道如何在循环中实现这一点。你能帮我吗Airflow 循环中的DAG任务依赖关系,airflow,directed-acyclic-graphs,Airflow,Directed Acyclic Graphs,我有一个DAG需要重新编译不同品牌的客户列表。使用两个参数brand和listtype调用脚本 我需要品牌同时运行,但是列表类型依赖于前面的列表类型,但是我不知道如何在循环中实现这一点。你能帮我吗 BrandsToRun = ['A', 'B', 'C'] ListTypes = ['1', '2', '3'] # Defining the DAG #########################################################################
BrandsToRun = ['A', 'B', 'C']
ListTypes = ['1', '2', '3']
# Defining the DAG
################################################################################
with DAG(
'MusterMaster',
default_args = default_args,
description = 'x',
# schedule_interval = None
schedule_interval = '30 4 * * *',
catchup = False
) as MusterMaster:
for Brand in BrandsToRun:
for ListType in ListTypes:
ListLoad = BashOperator(
task_id='Load_'+str(Brand)+'_'+str(ListType),
bash_command = """python3 '/usr/local/bin/MusterMaster.py' {0} {1}""".format(Brand[0], ListType[0]),
pool='logs'
)
ListLoad
我希望任务具有这样的依赖结构,但我无法理解。Brand应该同时运行,但是ListType应该依赖于前面的ListType
集合A 1>>集合A 2>>集合A 3
集合B1>>集合B2>>集合B3
集合C1>>集合C2>>集合C3
如何才能最好地完成此任务?您可以:
for Brand in BrandsToRun:
list = []
for ListType in ListTypes:
list.append(BashOperator(
task_id='Load_'+str(Brand)+'_'+str(ListType),
bash_command = """python3 '/usr/local/bin/MusterMaster.py' {0} {1}""".format(Brand[0], ListType[0]),
pool='logs'))
if len(list) > 1:
list[-2] >> list[-1]
这将给你: