Search code examples
airflowtimedelta

How do we apply execution_timeout to any task in airflow. It should also give out an email notification if a task fails


I want this task to fail and give out an error notification.

t1 = BashOperator(
    task_id='sleep_for_10s',  # Cause the task to miss the SLA
    bash_command='sleep 10s',
    execution_timeout=datetime.timedelta(seconds = 5),
    #sla=datetime.timedelta(microseconds=10),  # SLA for the task
    dag=dag)

Solution

  • You can use email_on_failure parameter.

    t1 = BashOperator(
        task_id='sleep_for_10s',  # Cause the task to miss the SLA
        bash_command='sleep 10s',
        execution_timeout=datetime.timedelta(seconds = 5),
        email=['airflow@example.com'],
        email_on_failure=True,
        dag=dag)
    

    Note that sla miss doesn't necessarily mean failure of task.