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

如何通过Airflow 2.2.5 REST API获取DAG的下一次调度运行时间

Airflow 2.2.5 REST API 获取DAG下一次调度运行时间的替代方案

在Airflow 2.4.2中可通过get_dag接口返回的next_dagrun字段直接获取DAG下一次调度时间,但2.2.5版本的API没有该字段,可通过以下方式实现相同功能:

  • 调用DAGRunApi的get_dag_runs方法,筛选状态为future的DAG运行实例,取排序后第一条的execution_date作为下一次调度时间。

对应的Python代码示例:

from airflow_client.client.api import dag_run_api

with airflow_client.client.ApiClient(conf) as api_client:
    api_instance = dag_run_api.DAGRunApi(api_client)
    dag_id = build_dag_id(name)

    # 筛选未来状态的DAG运行,按执行时间升序排列,仅取第一条结果
    response = api_instance.get_dag_runs(
        dag_id=dag_id,
        state="future",
        order_by="execution_date",
        limit=1
    )

    # 若有结果则取第一条的execution_date,否则为None
    next_run = response[0]["execution_date"] if response else None

注意:如果返回结果为空,说明当前没有已调度的未来DAG运行实例,需检查DAG的调度配置(如schedule_interval是否正确设置、DAG是否处于激活状态等)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 10:54:56