Email notification on failure

Configure an Apache Airflow DAG to notify by using email on failure in Cloud Composer.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample

Python

from airflow import models
default_dag_args = {
    'start_date': yesterday,
    # Email whenever an Operator in the DAG fails.
    'email': models.Variable.get('email'),
    'email_on_failure': True,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': datetime.timedelta(minutes=5),
    'project_id': models.Variable.get('gcp_project')
}

with models.DAG(
        'composer_sample_bq_notify',
        schedule_interval=datetime.timedelta(weeks=4),
        default_args=default_dag_args) as dag:

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser