0
0
Apache Airflowdevops~10 mins

Timetables for complex schedules 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 create a daily timetable starting at midnight.

Apache Airflow
from airflow.timetables.base import Timetable
class DailyMidnightTimetable(Timetable):
    def infer_manual_data(self, run_after: float):
        return run_after
    def next_dagrun_info(self, last_automated: float | None, now: float) -> float:
        return [1]
Drag options to blanks, or click blank then click option'
Alast_automated + 3600
Bnow + 86400
C(now // 86400 + 1) * 86400
Dnow
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'now + 86400' which schedules at the same time next day, not midnight
Using 'last_automated + 3600' which is hourly from last run
Returning 'now' for immediate execution
2fill in blank
medium

Complete the code to create a timetable that triggers every Monday at 9 AM.

Apache Airflow
from airflow.timetables.base import Timetable
from datetime import datetime, timedelta
class WeeklyMonday9AMTimetable(Timetable):
    def next_dagrun_info(self, last_automated: float | None, now: float) -> float:
        next_run = datetime.fromtimestamp(now).replace(hour=9, minute=0, second=0, microsecond=0)
        while next_run.weekday() != [1] or next_run.timestamp() <= now:
            next_run += timedelta(days=1)
        return next_run.timestamp()
Drag options to blanks, or click blank then click option'
A0
B4
C6
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1, which is Tuesday, not Monday
Confusing with systems where Sunday is 0
3fill in blank
hard

Fix the error in the code to correctly calculate the next run time for a timetable that triggers every hour on the half hour.

Apache Airflow
from airflow.timetables.base import Timetable
from datetime import datetime, timedelta
class HourlyHalfHourTimetable(Timetable):
    def next_dagrun_info(self, last_automated: float | None, now: float) -> float:
        current = datetime.fromtimestamp(now)
        next_run = current.replace(minute=30, second=0, microsecond=0)
        if current.minute >= 30:
            next_run += timedelta(hours=[1])
        return next_run.timestamp()
Drag options to blanks, or click blank then click option'
A0
B1
C30
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 0 hours, leaving next_run in the past
Confusing minutes with hours (30 or 60)
4fill in blank
hard

Fill both blanks to create a timetable that triggers every weekday at 8 AM.

Apache Airflow
from airflow.timetables.base import Timetable
from datetime import datetime, timedelta
class Weekday8AMTimetable(Timetable):
    def next_dagrun_info(self, last_automated: float | None, now: float) -> float:
        next_run = datetime.fromtimestamp(now).replace(hour=[1], minute=0, second=0, microsecond=0)
        while next_run.timestamp() <= now or next_run.weekday() [2] 5:
            next_run += timedelta(days=1)
        return next_run.timestamp()
Drag options to blanks, or click blank then click option'
A8
B<
C>=
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Setting hour to 7 or other value instead of 8
Using '< 5' which skips weekdays (Mon-Fri) instead of weekends
5fill in blank
hard

Fill all three blanks to create a timetable that triggers on the first day of each month at midnight.

Apache Airflow
from airflow.timetables.base import Timetable
from datetime import datetime, timedelta
class MonthlyFirstDayMidnightTimetable(Timetable):
    def next_dagrun_info(self, last_automated: float | None, now: float) -> float:
        current = datetime.fromtimestamp(now)
        year = current.year
        month = current.month + [1]
        if month > 12:
            month = [2]
            year += 1
        next_run = datetime(year, month, [3], 0, 0, 0)
        return next_run.timestamp()
Drag options to blanks, or click blank then click option'
A1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 for day (invalid date)
Failing to reset month to 1 or increment year on overflow
Adding 0 instead of 1 to month