Is it possible to update/overwrite the Airflow [‘dag_run’].conf?

白昼怎懂夜的黑 提交于 2019-12-24 01:17:30

问题


We typically start Airflow DAGs with the trigger_dag CLI command. For example:

airflow trigger_dag my_dag --conf '{"field1": 1, "field2": 2}'

We access this conf in our operators using context[‘dag_run’].conf

Sometimes when the DAG breaks at some task, we'd like to "update" the conf and restart the broken task (and downstream dependencies) with this new conf. For example:

new conf --> {"field1": 3, "field2": 4}

Is it possible to “update” the dag_run conf with a new json string like this?

Would be interested in hearing thoughts on this, other solutions, or potentially ways to avoid this situation to begin with.

Working with Apache Airflow v1.10.3

Thank you very much in advance.


回答1:


This seems like a good use-case of Airflow Variables. If you were to read your configs from Variables you can easily see and modify the configuration inputs from the Airflow UI itself.


You can even go creative and automate that updation of config (which is now stored in a Variable) before re-running a Task / DAG via another Airflow task itself. See With code, how do you update and airflow variable



来源:https://stackoverflow.com/questions/57062998/is-it-possible-to-update-overwrite-the-airflow-dag-run-conf

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