气流Jinja渲染模板 [英] Airflow Jinja Rendered Template

查看:127
本文介绍了气流Jinja渲染模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经能够使用BaseOperator中的功能 render_template 成功渲染Jinja模板。



我的问题是,是否有人知道在 Rendered Rendered Template 标签下将呈现的字符串输入UI的要求? / p>

在用户界面中引用此标签:



在此提供任何帮助或指导。

解决方案

如果在Operator中使用模板字段,则将在模板字段中显示创建的字符串。例如。使用BashOperator:

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

然后bash命令将通过模板引擎进行解析(因为其中包括Jinja字段),稍后您可以在Web UI中看到您提到的解析结果。



不过,必须对字段进行模板化。可以在 templated_fields 字段的代码中看到。对于BashOperator(请参见此处的代码 https://github.com /apache/incubator-airflow/blob/master/airflow/operators/bash_operator.py )这是:

  template_fields =('bash_command','env')

BashOperator中的其他字段不会被解析。



您可以使用宏命令(请参见 https://airflow.apache.org/code.html#macros )或来自xcom的信息(请参见 https://airflow.apache.org/concepts.html?highlight=xcom#xcoms )在模板字段中。


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.

解决方案

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.

这篇关于气流Jinja渲染模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆