如何在 Airflow 中的电子邮件操作员上附加文件

Spa*_*azz 6 airflow airflow-operator

每当我将文件参数添加到email_task我的运行失败时。

email_task = EmailOperator(    
           task_id='email_sample_data',    
           to='sample@sample.com',    
           subject='Forecast for the day',    
           html_content= "Sample",
           files=['/home/airflow/sample.html'],    
           dag=dag)
Run Code Online (Sandbox Code Playgroud)

我收到一个错误,提示找不到文件。气流在哪里选择我的文件,我需要在哪里上传文件,“文件”参数的正确语法是什么?

Ela*_*lad 3

Airflow 期望路径相对于 DAG 文件的存储位置。但是,由于文件是模板化字段,您可以使用template_search_path提供 Airflow 将查找的其他路径:

with DAG(
        ...
        template_searchpath = ['/home/airflow/'],
        ) as dag:
    email_task = EmailOperator(
        task_id='email_sample_data',
        to='sample@sample.com',
        subject='Forecast for the day',
        html_content="Sample",
        files=['/home/airflow/sample.html']
    )
Run Code Online (Sandbox Code Playgroud)