Python 中的 Apache Airflow 入门
Mike Metzger
Data Engineer
schedule 触发runningfailedsuccess

为 Dag 设定调度时,需关注:
start_date - 首次调度的日期/时间end_date - 可选,停止新实例的时间start_date 与 end_date 均使用 datetime(year, month, day) 对象,例如: from pendulum import datetime
start_date=datetime(2026, 4, 10, tz="UTC")
schedule 表示:
start_date 与 end_date 之间cron 语法、内置预设或 timedelta 定义
* 表示每个间隔都运行(如每分钟、每天)
0 12 * * * # 每天中午运行
* * 25 2 * # 2 月 25 日每分钟运行一次
0,15,30,45 * * * * # 每 15 分钟运行
预设:
等效 cron:
0 * * * *0 0 * * *0 0 * * 00 0 1 * *0 0 1 1 *Airflow 有三个特殊的 schedule 预设:
None - 从不调度,用于手动触发的 Dag@once - 只调度一次@continuous - 在上次运行结束后立即运行pendulum.durationduration(hours=6)duration(minutes=30)from pendulum import duration
@dag(
dag_id="example_dag"
schedule=duration(days=2)
)
schedule 参数:@dag(
dag_id="example_dag",
schedule="0 12 * * *"
)
@dag(
dag_id="example_dag",
schedule="@daily"
)
为 Dag 设置调度时,Airflow 将:
start_date + schedule 时刻调度'start_date': datetime(2026, 2, 25, tz="UTC")
'schedule': @daily
最早运行时间为 2026 年 2 月 26 日
Python 中的 Apache Airflow 入门