【问题标题】:Airflow execution_date wrong value气流 execution_date 错误值
【发布时间】:2020-12-07 16:03:57
【问题描述】:

我必须运行 spark 作业,并且在该 spark 作业中,我们必须将日期作为参数传递以读取当前目录。我正在使用 Airflow 来安排工作。以下是一些信息

开始日期

import pendulum
local_tz = pendulum.timezone("Asia/Kolkata")
start_date': datetime(year=2020, month=8, day=3,tzinfo=local_tz)

schedule_interval

schedule_interval='20 0 * * *'

在工作中传递的值

{{ (execution_date + macros.timedelta(hours=5,minutes=30) - macros.timedelta(days=1)).strftime("%Y/%m/%d") }}

我们必须在前一天的午夜运行这项工作,但是这个表达式给了我前天的日期。我添加了 5:30,因为我们的气流使用 UTC 时间。

谁能解释一下这里发生了什么?

谢谢

【问题讨论】:

  • 我认为 spark 不关心时区。
  • 这次是 schedule_interval。如果我没有更改时区,那么作业将触发 UTC 午夜而不是我当地的午夜,直到那时我的数据目录还没有准备好读取。

标签: python apache-spark airflow scheduler directed-acyclic-graphs


【解决方案1】:

以下是执行日期的定义

The execution time in Airflow is not the actual run time, but rather the start timestamp of its schedule period. For example, the execution time of the first DAG run is 2019–12–05 7:00:00, though it is executed on 2019–12–06.Dec 9, 2019

取自https://towardsdatascience.com/apache-airflow-tips-and-best-practices-ff64ce92ef8#:~:text=The%20execution%20time%20in%20Airflow,on%202019%E2%80%9312%E2%80%9306

您的值中不需要 macros.timedelta(days=1)).strftime("%Y/%m/%d")

【讨论】:

  • 我已经删除了您提到的上述值,但即使现在 execution_date 指向的是 2 天前。如何重置其值使其指向前一天??
  • 气流运行的服务器的时区是什么(我假设 UTC)? start_date 是什么?能否请您给出这个 start_date=datetime.datetime(2020, 08, 21), schedule_interval='0 0 * * *' 并删除 execution_date
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-28
  • 1970-01-01
  • 1970-01-01
  • 2018-06-12
  • 2022-06-16
相关资源
最近更新 更多