Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of timedelta
Using an integer directly
Using datetime.now() instead of timedelta
✗ Incorrect
The sla parameter expects a timedelta object to define the SLA duration.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'email_on_failure' instead
Using 'email_on_retry' instead
Using 'email_on_success' instead
✗ Incorrect
To receive notifications on SLA misses, set email_on_sla_miss to True.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'task_instance' directly as parameter
Using 'dag_run' instead of context
Using 'kwargs' without unpacking
✗ Incorrect
The SLA miss callback receives a context dictionary with task and DAG info.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for parameter and variable
Not accessing task_instance from context
✗ Incorrect
The callback receives context and accesses task_instance from it.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong email notification key
Not assigning the callback function
Using wrong SLA value type
✗ Incorrect
Set email_on_sla_miss to True, assign the callback function, and define SLA as timedelta.