Skip to main content
 首页 » 编程设计

python之Airflow DAG 预定日期晚了一周

2025年05月04日19xing901022

我有一个 DAG 计划在每周一 10AM 运行。这是我的 dag 定义

DAG = models.DAG( 
  dag_id="etl", schedule_interval="0 10 * * 1", start_date=datetime(2018, 10, 1),  
  default_args=args 
) 
 
latest_only = LatestOnlyOperator(task_id="latest", dag=DAG) 
 
extract = PythonOperator( 
task_id="extract", python_callable=extract,  dag=DAG) 
 
extract.set_upstream(latest_only) 

它在每周一的 10AM 触发。它在今天(05/06/2019)运行,但预定日期为 2019-04-29 14:00:00 任务实例具有以下日期

execution_date : 2019-04-29T14:00:00+00:00 
start_date : 2019-05-06 14:19:48.527488+00:00 
end_date : 2019-05-06 14:19:54.225001+00:00 

它在上周一(4 月 29 日)运行良好,日期正确,在 dag 历史记录中,它现在显示在 4 月 29 日运行了 2 次。可能是什么原因造成的?

请您参考如下方法:

有一个 chapter on Scheduling in the Airflow documentation ,其中指出:

Note that if you run a DAG on a schedule_interval of one day, the run stamped 2016-01-01 will be trigger soon after 2016-01-01T23:59. In other words, the job instance is started once the period it covers has ended.

Let’s Repeat That The scheduler runs your job one schedule_interval AFTER the start date, at the END of the period.

您正在经历这样的事情:今天 (2019-05-06) 为最新的“完成”间隔创建了一个 DagRun,这意味着从 2019-04-29 开始的一周。

这样想可能会有所帮助:如果您想周期性地处理一些数据,您需要在数据准备好那个时期后开始处理它。