我似乎无法让它发挥作用。
我试图每天发送一个给定的文件,其名称类似于“file_{{ds_nodash}}.csv”。
问题是我似乎无法添加此名称作为文件名,因为它似乎无法使用。在电子邮件的正文或主题中效果很好,而不是在名称上。
下面以 dag 为例:
local_file = 'file-{{ds_nodash}}.csv'
send_stats_csv = EmailOperator(
task_id='send-stats-csv',
to=['[email protected] /cdn-cgi/l/email-protection'],
subject='Subject - {{ ds }}',
html_content='Here is the new file.',
files=[local_file],
dag=dag)
错误代码:
没有这样的文件或目录:u'file-{{ds_nodash}}.csv'
如果我按字面意思写下它,并附上给定的日期,它就可以完美地工作。
我哪里错了?我该怎么办?
任何帮助,将不胜感激。
Thanks.
P.D.从 Airflow 的文档中复制粘贴 - “Airflow 引擎默认传递一些可在所有模板中访问的变量”。https://airflow.incubator.apache.org/code.html https://airflow.incubator.apache.org/code.html
如果我理解正确的话,这些变量在执行中是可以访问的,所以如果我正在执行 dag,应该可以找到该文件,对吧?我尝试过测试任务或回填 dag,但都没有成功。
Airflow Operators 定义哪些字段是模板字段。对于 EmailOperator,只有主题和 html_content 字段被设置为模板。
class EmailOperator(BaseOperator):
...
template_fields = ('subject', 'html_content')
template_ext = ('.html',)
See: https://airflow.incubator.apache.org/_modules/email_operator.html https://airflow.incubator.apache.org/_modules/email_operator.html
来自 Airflow Gotcha 的页面 (https://gtoonstra.github.io/etl-with-airflow/gotchas.html https://gtoonstra.github.io/etl-with-airflow/gotchas.html)
并非运算符中的所有参数都是模板化的,因此您不能在任何地方使用 Jinja 模板。 Jinja 模板仅适用于在 template_fields 中列出的运算符中的字段...
要使其正常工作,您必须从 EmailOperator 派生一个新类并添加文件数组的模板。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)