Challenge - 5 Problems
Airflow Timetable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of a complex Airflow timetable with multiple intervals
Given this Airflow timetable code, what is the next scheduled run date after 2024-06-01 00:00 UTC?
Apache Airflow
from airflow.timetables.interval import CronDataInterval from airflow.timetables.base import Timetable from pendulum import datetime class CustomTimetable(Timetable): def infer_manual_data_interval(self, run_after: datetime): return None def next_dagrun_info(self, last_automated_data_interval, restriction): # Schedule every Monday and Friday at 10:00 UTC from airflow.timetables.interval import CronDataInterval from pendulum import datetime if last_automated_data_interval is None: next_start = datetime(2024, 6, 3, 10, 0, 0, tz='UTC') # Monday else: last_start = last_automated_data_interval.start if last_start.weekday() == 0: # Monday next_start = last_start.add(days=4) # Friday else: next_start = last_start.add(days=3) # Next Monday return CronDataInterval(next_start, next_start.add(hours=1)) custom_tt = CustomTimetable() last_interval = None restriction = None next_run = custom_tt.next_dagrun_info(last_interval, restriction).start print(next_run)
Attempts:
2 left
💡 Hint
Think about the first Monday after June 1st, 2024.
✗ Incorrect
The timetable schedules runs on Mondays and Fridays at 10:00 UTC. Since June 1, 2024 is a Saturday, the next Monday is June 3, 2024 at 10:00 UTC.
🧠 Conceptual
intermediate1:30remaining
Understanding Airflow Timetable restrictions
Which statement best describes the role of the 'restriction' parameter in Airflow's Timetable.next_dagrun_info method?
Attempts:
2 left
💡 Hint
Think about how Airflow avoids scheduling runs too early or too late.
✗ Incorrect
The 'restriction' parameter provides earliest and latest datetime boundaries to ensure the timetable does not schedule runs outside these limits.
🔀 Workflow
advanced2:30remaining
Configuring a DAG with a custom timetable for multiple schedules
You want to create an Airflow DAG that runs every weekday at 9:00 AM and also on the 1st of every month at 12:00 PM. Which approach correctly implements this using a custom timetable?
Attempts:
2 left
💡 Hint
Think about how to combine two different schedules in one DAG timetable.
✗ Incorrect
A custom Timetable class can programmatically return the next run date for either schedule, alternating or choosing the earliest. Cron expressions cannot combine these two schedules cleanly in one expression.
❓ Troubleshoot
advanced2:30remaining
Diagnosing unexpected DAG run times with a custom timetable
A DAG with a custom timetable runs at unexpected times, including weekends, despite the timetable code specifying only weekdays. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check how the timetable calculates the next run date based on the last run.
✗ Incorrect
If the timetable's logic for calculating the next run date is flawed, it may return dates outside the intended schedule, such as weekends.
✅ Best Practice
expert3:00remaining
Best practice for implementing complex schedules in Airflow
What is the best practice when implementing a complex schedule that requires multiple non-overlapping intervals in Airflow?
Attempts:
2 left
💡 Hint
Consider maintainability and correctness for complex schedules.
✗ Incorrect
Custom Timetable classes provide precise control and clarity for complex schedules, avoiding the limitations and confusion of combining multiple cron expressions or manual triggers.