Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Success mail in Airflow

Tags:

How can I get success mail in airflow after complete execution of a each dags.

This is what I have tried. I am tring to get a success mail on completion of dags Can anyone will help me out. I have import all the files that are required.

i = datetime.now()

default_args = {
'owner': 'owner',
'depeneds_on_past': False,
'start_date': datetime(i.year, i.month, i.day-1),
'email': ['[email protected]'],
'email_on_failure': True,
'email_on_retry': True,
'email_on_success': True,
'retries': 0,
'retry_delay': timedelta(minutes=10)
}

dag = DAG('update', default_args = default_args, 
schedule_interval="0 3 * * *")


t0 = PythonOperator(
task_id='clear',
python_callable=empty_tables,
email_on_failure=True,
email_on_success=True,
email=['[email protected]'],
dag=dag
)

# Add tasks now 
t1 = BashOperator(
task_id='export',
bash_command=script,
dag=dag
)


t2 = PythonOperator(
task_id='load',
python_callable=load,
email_on_failure=True,
email_on_success=True,
email=['[email protected]'],
dag=dag
)



t0 >> t1 >> t2
like image 833
Avinash Kumar Avatar asked Nov 29 '18 07:11

Avinash Kumar


2 Answers

You need to configure SMTP server and add this to airflow.cfg file.

Check https://stackoverflow.com/a/51837049/5691525 to see how you can setup SMTP Server for Airflow Email alerts using Gmail.

like image 78
kaxil Avatar answered Sep 30 '22 05:09

kaxil


While there exists 'email_on_failure' key to raise alerts in case of failed task, there isn't any key defined in airflow code as 'email_on_success'. Hence, in order to trigger an email alert on success, you would have to make use of 'on_success_callback'

like image 37
IshitaV Avatar answered Sep 30 '22 06:09

IshitaV