In Airflow, what is the main purpose of setting a task failure callback function?
Think about what you want to happen right after a task fails.
A task failure callback lets you run custom code when a task fails, like sending an email alert or logging extra info. It does not retry or skip tasks automatically.
Given this Airflow task failure callback function, what will be printed when a task fails?
def failure_callback(context): task_instance = context['task_instance'] print(f"Task {task_instance.task_id} failed at {task_instance.end_date}")
Look at what the print statement outputs using the context dictionary.
The callback prints the task ID and the time it ended, which is when it failed.
Which code snippet correctly assigns a failure callback function named notify_failure to an Airflow PythonOperator task?
Check the exact parameter name for failure callbacks in Airflow operators.
The correct parameter to assign a failure callback is on_failure_callback. Other options are invalid parameter names.
You assigned a failure callback to a task, but it never runs when the task fails. What is the most likely reason?
Check how the failure callback is assigned to the task.
If the failure callback is not assigned using the on_failure_callback parameter, Airflow will not know to run it on failure.
Arrange the steps in the correct order when an Airflow task fails and a failure callback is set.
Think about what happens first: failure, marking state, then callback.
First the task fails, then Airflow marks it failed, then it calls the failure callback, which performs actions.