Airflow

Airflow XComs Email 전송

pepega 2022. 3. 18. 18:19

Airflow로 Email 전송하는 글을

포스팅했었다.

 

https://pepega.tistory.com/47

 

블로그 코드는

https://github.com/GHGHGHKO/airflow/blob/master/dags/email_xcom_test.py

 

전 포스팅 내용을 기반으로

DAG을 만들었다.

    email_operator = EmailOperator(
        task_id='send_email',
        to='receiver@example.com',
        subject='[TEST] 테스트 메일입니다.',
        html_content="""
                        테스트 메일입니다.<br/><br/> 
                        ninja template<br/>
                        {{ data_interval_start }}<br/>
                        {{ ds }}<br/>
                        {{ task_instance.xcom_pull(dag_id='postgres_db_operator', task_ids='postgres-db-task') }}<br/>
                    """,
    )

 

dag_id='postgres_db_operator', task_ids='postgres-db-task'

내용(XCom)은 아래와 같다.

 

Key Value Timestamp Logical Date Task Id Dag Id
return_value [['test', 'ko', 'pepega'], ['cuphead', 'teapot', 'cup'], ['mugman', 'teapot1', 'cup1']] 2022-03-17, 09:02:09 2022-02-28, 15:00:00 postgres-db-task  postgres_db_operator

html_content 안에

template에 XCom 내용을 추가하였다.

 

메일을 전송해본다.

 

DAG는 잘 실행됐다.

 

 

메일도 원하는 내용으로 발송됐다.