Adding retries
You've noticed that one particular Dag is failing often on a task that extracts data from a given source. Frustratingly, running the task a few minutes later seems to remedy the problem. After learning about the retry functionality in Airflow Dags, you decide to implement retries on this task to keep from restarting it manually.
The dag, task, and timedelta are already imported for you.
This exercise is part of the course
Introduction to Apache Airflow in Python
Exercise instructions
- Set the
extract_datatask to retry 3 times before failing. - Add a delay of 10 minutes between retries on the
extract_datatask.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
@dag(schedule="@daily", start_date=datetime(2026, 5, 1))
def etl_pipeline():
# Set retries and retry delay on extract_data
@task(____=3, ____=____(minutes=10))
def extract_data():
print("Extracting data from source...")
@task()
def process_source_data():
print("Now processing data...")
extract_data() >> process_source_data()
etl_pipeline()