0
0
Apache Airflowdevops~10 mins

SLA misses and notifications in Apache Airflow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set an SLA for a task in Airflow.

Apache Airflow
task = PythonOperator(task_id='my_task', python_callable=my_func, sla=[1])
Drag options to blanks, or click blank then click option'
Adatetime.now()
B30
C'30 minutes'
Dtimedelta(minutes=30)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of timedelta
Using an integer directly
Using datetime.now() instead of timedelta
2fill in blank
medium

Complete the code to enable SLA miss notifications via email in Airflow's DAG.

Apache Airflow
default_args = {'email': ['admin@example.com'], 'email_on_[1]': True}
Drag options to blanks, or click blank then click option'
Asla_miss
Bsuccess
Cretry
Dfailure
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'email_on_failure' instead
Using 'email_on_retry' instead
Using 'email_on_success' instead
3fill in blank
hard

Fix the error in the SLA miss callback function definition.

Apache Airflow
def sla_miss_callback([1]):
    print(f"SLA missed for task: [1]['task_instance'].task_id")
Drag options to blanks, or click blank then click option'
Adag_run
Btask_instance
Ccontext
Dkwargs
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'task_instance' directly as parameter
Using 'dag_run' instead of context
Using 'kwargs' without unpacking
4fill in blank
hard

Fill both blanks to correctly access the task instance and send an email in the SLA miss callback.

Apache Airflow
def sla_miss_callback([1]):
    task_instance = [2]['task_instance']
    send_email('admin@example.com', f"SLA missed for {task_instance.task_id}")
Drag options to blanks, or click blank then click option'
Acontext
Bkwargs
Dparams
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for parameter and variable
Not accessing task_instance from context
5fill in blank
hard

Fill all three blanks to define a DAG with SLA miss callback and email notification.

Apache Airflow
default_args = {
    'owner': 'airflow',
    'start_date': datetime(2024, 1, 1),
    'email': ['admin@example.com'],
    'email_on_[1]': True,
    'sla_miss_callback': [2]
}

dag = DAG('sla_example', default_args=default_args, schedule_interval='@daily')

task = PythonOperator(task_id='task1', python_callable=my_func, sla=[3], dag=dag)
Drag options to blanks, or click blank then click option'
Asla_miss
Bsla_miss_callback
Ctimedelta(minutes=45)
Demail_on_failure
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong email notification key
Not assigning the callback function
Using wrong SLA value type