---

title: Airflow DAG 调度与依赖管理实践

keywords:

  • Airflow
  • DAG
  • schedule_interval
  • retries
  • 依赖管理

description: 使用 Airflow 2.x 编写 DAG 并管理任务依赖与重试策略,提供可运行的示例与调度配置。

categories:

  • 文章资讯
  • 技术教程

---

Airflow DAG 调度与依赖管理实践

from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.python import PythonOperator

def extract():
    print("extract")

def transform():
    print("transform")

def load():
    print("load")

default_args = {
    "owner": "data",
    "retries": 2,
    "retry_delay": timedelta(minutes=5),
}

with DAG(
    dag_id="etl_pipeline",
    start_date=datetime(2025, 1, 1),
    schedule_interval="0 * * * *",
    catchup=False,
    default_args=default_args,
) as dag:
    t1 = PythonOperator(task_id="extract", python_callable=extract)
    t2 = PythonOperator(task_id="transform", python_callable=transform)
    t3 = PythonOperator(task_id="load", python_callable=load)

    t1 >> t2 >> t3

调度与依赖

  • 通过 schedule_interval 设置定时;catchup=False 关闭补跑
  • 使用位移运算符 >> 管理任务拓扑

总结

明确的调度与依赖配置能提升管道的稳定性与可维护性。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部