I'm currently working on a DAG that will email a list of users whether the DAG has completed successfully or has failed. I am trying to have the flow of the DAG look like the example here:
from datetime import datetimefrom airflow import DAGfrom airflow.operators.python_operator import PythonOperatorfrom airflow.operators.email_operator import EmailOperatordef print_hello(): return 'Hello world!'default_args = {'owner': 'peter','start_date':datetime(2018,8,11),}dag = DAG('hello_world', description='Simple tutorial DAG', schedule_interval='* * * * *', default_args = default_args, catchup=False)hello_operator = PythonOperator(task_id='hello_task', python_callable=print_hello, dag=dag)email_success = EmailOperator( task_id='send_email', to='to@gmail.com', subject='Airflow Alert Success', html_content="""<h3>Email Test Success</h3> """, dag=dag)email_failure = EmailOperator( task_id='send_email', to='to@gmail.com', subject='Airflow Alert Failure', html_content="""<h3>Email Test Failed</h3> """, dag=dag)hello_operator.set_downstream(email_success,email_failure)
Is there a built in operator that I can use with airflow to decide whether the email_success operator is sent when the DAG completes or if email_failure operator is executed when the DAG fails for any reason?
Thank you