【问题标题】:Getting the date of the most recent successful DAG execution获取最近一次成功执行 DAG 的日期
【发布时间】:2020-09-06 19:49:46
【问题描述】:

我希望在 Airflow 中创建一个转换,并且我想确保从我的源中获取自上次运行 DAG 以来的所有数据以更新我的目标表。为此,我希望能够获得最近一次成功的执行。

我发现了这个:Apache airflow macro to get last dag run execution time,它让我到达了最终目标,但是,这只是 DAG 执行的最后一次,无论它是否成功。

SELECT col1, col2, col3
FROM schema.table
WHERE table.updated_at > '{{ last_dag_run_execution_date(dag) }}';

如果执行失败(由于连接或类似原因),last_dag_run_execution_date(dag) 将更新,但我们错过了前一次 DAG 运行的执行。

理想情况下,这将拉取最近的非失败执行。或者如果有人有任何想法我可以如何实现这一点,请告诉我

【问题讨论】:

标签: airflow


【解决方案1】:

我最终将引用问题中的函数更改为使用 latest_execution_date,这是 Airflow 中的预定义宏,如下所示:

def get_last_dag_run(dag):
    last_dag_run = dag.latest_execution_date
    if last_dag_run is None: 
        return '2013-01-01'
    else:
        return last_dag_run

目前似乎对我有用。

【讨论】:

  • 返回是否同时显示 dag 名称和最后执行日期?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多