Airflow DAG dynamic structure

寵の児 提交于 2020-01-04 14:24:09

问题


I was looking for a solution where I can decide the dag structure when the dag is triggered as I'm not sure about the number of operators that I'll have to run.

Please refer below for the execution sequence that I'm planning to create.

           |-- Task B.1 --|                  |-- Task C.1 --|
           |-- Task B.2 --|                  |-- Task C.2 --|
  Task A --|-- Task B.3 --|---> Task  B ---> |-- Task C.3 --|
           |     ....     |                  |     ....     |
           |-- Task B.N --|                  |-- Task C.N --|

I'm not sure about the value of N.

Is this possible in airflow. If so, how do I achieve this.

Thanks in Advance


回答1:


I had to do something similar in the past, I wrote a DAG which read from a YAML file which defined what tasks to create.

My situation was that the number of tables that I was extracting data from could change every week, instead of re-deploying the DAG to production every time I needed to add a new table I pointed the DAG to a YAML file which described which tables to extract. Every time a new table came along I would simply edit the YAML file with the new table details.

I think it gets a bit trickier if an upstream task needs to be run first which then determines how many downstream tasks to run like in the following - but similar - question:

Generating dynamic tasks in airflow based on output of an upstream task



来源:https://stackoverflow.com/questions/49114565/airflow-dag-dynamic-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!