Airflow Jinja Rendered Template

限于喜欢 提交于 2019-12-21 13:40:54

问题


I've been able to successfully render Jinja Templates using the function within the BaseOperator, render_template.

My question is does anyone know the requirements to get rendered strings into the UI under the Rendered or Rendered Template tab?

Referring to this tab in the UI:

Any help or guidance here would be appreciated.


回答1:


If you are using templated fields in an Operator, the created strings out of the templated fields will be shown there. E.g. with a BashOperator:

example_task = BashOperator(
    task_id='task_example_task',
    bash_command='mycommand --date {{ task_instance.execution_date }}',
    dag=dag,
)

then the bash command would get parsed through the template engine (since a Jinja field is included) and later on you could see the result of this parsing in the web UI as you mentioned.

The fields must be templated, though. This can be seen in the code in the field templated_fields. For BashOperator (see code here https://github.com/apache/incubator-airflow/blob/master/airflow/operators/bash_operator.py) this is:

template_fields = ('bash_command', 'env')

Other fields in the BashOperator will not be parsed.

You can use macro commands (see here https://airflow.apache.org/code.html#macros) or information from xcom (see here https://airflow.apache.org/concepts.html?highlight=xcom#xcoms) in templated fields.



来源:https://stackoverflow.com/questions/50184992/airflow-jinja-rendered-template

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