You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache Airflow 2.5.2中DAG无法自动触发问题求助

问题描述

原使用Apache Airflow 1.10.14时DAG运行正常,升级至2.5.2版本并采用Kubernetes Executor后,DAG无法自动调度,但手动触发可正常执行。日志中出现以下信息:

{kubernetes_executor.py:494} INFO - Found 0 queued task instances

测试DAG代码如下:

from datetime import datetime, timedelta

from airflow import DAG
   
from airflow.operators.bash import BashOperator

with DAG(
    "migration_test",
    default_args={
        "depends_on_past": False,
        "retries": 1,
        "retry_delay": timedelta(minutes=5),
    },

    description="Migration test",
    schedule='*/3 * * * *',
    start_date=datetime(2023, 4, 30),
    catchup=False,
    tags=["common"],
) as dag:

    t1 = BashOperator(
        task_id="print_date",
        bash_command="date",
    )

    t2 = BashOperator(
        task_id="sleep",
        depends_on_past=False,
        bash_command="sleep 5",
        retries=3,
    )

t1 >> t2
需调整的配置参数

以下是针对Airflow 2.5.2 + Kubernetes Executor场景,解决自动调度失效问题的关键配置调整:

调度器核心配置(airflow.cfg)

  • scheduler_job_heartbeat_sec:设置为5
    Airflow 2.x中调度器通过心跳机制维持活跃状态,若心跳间隔过长,系统会判定调度器离线,停止生成待调度任务实例。1.10版本无此严格校验,升级后需缩短心跳间隔确保调度器被标记为在线。
  • max_tis_per_query:调整为512
    提升调度器单次查询元数据库的任务实例数量,避免因查询限制导致待调度任务被遗漏,确保所有符合条件的任务能被纳入调度队列。
  • scheduler_health_check_threshold:设置为30
    定义调度器健康检查的超时阈值,确保即使调度器短暂延迟,也不会被判定为异常,保证任务调度流程持续运行。

Kubernetes Executor配置(airflow.cfg)

  • kubernetes_executor_queue:确认值为default(若DAG未指定自定义队列)
    Airflow 2.x对Kubernetes Executor的队列路由逻辑做了优化,需确保Executor监听的队列与DAG默认队列一致,否则任务实例无法被Executor拾取。1.10版本中队列匹配逻辑较宽松,升级后需严格对齐。
  • kubernetes_executor_worker_pods_creation_batch_size:设置为10
    控制Executor批量创建Pod的数量,避免因批量过小导致任务调度延迟,确保待执行任务能被快速分配到Pod中。

数据库连接配置(airflow.cfg)

  • sql_alchemy_pool_size:调整为20,sql_alchemy_max_overflow设置为40
    Airflow 2.x调度器和Executor对数据库连接的需求更高,增大连接池大小可避免因连接不足导致任务实例无法被读取或写入,确保调度流程的数据库交互稳定。

DAG解析配置(airflow.cfg)

  • min_file_process_interval:设置为30
    确保调度器每隔30秒重新解析一次DAG文件,避免因DAG文件未被及时加载导致调度规则(如schedule)未生效,保证自动调度触发器能被正确识别。

内容的提问来源于stack exchange,提问作者Gags08

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 01:39:56