python - airflow trigger_dag execution_date 是第二天,为什么?

标签 python airflow

最近我对 Airflow 进行了太多测试,以至于 execution_date 有一个问题运行时 airflow trigger_dag <my-dag> .

我了解到 execution_date不是我们第一次从here想到的:

Airflow was developed as a solution for ETL needs. In the ETL world, you typically summarize data. So, if I want to summarize data for 2016-02-19, I would do it at 2016-02-20 midnight GMT, which would be right after all data for 2016-02-19 becomes available.

start_date = datetime.combine(datetime.today(),
                              datetime.min.time())

args = {
    "owner": "xigua",
    "start_date": start_date
}
dag = DAG(dag_id="hadoopprojects", default_args=args,
          schedule_interval=timedelta(days=1))


wait_5m = ops.TimeDeltaSensor(task_id="wait_5m",
                              dag=dag,
                              delta=timedelta(minutes=5))

以上代码是我日常工作流程的开始部分,第一个任务是一个 TimeDeltaSensor,它在实际工作之前再等待 5 分钟,所以这意味着我的 dag 将在 2016-09-09T00:05:00 被触发。 , 2016-09-10T00:05:00 ……等

在 Web UI 中,我可以看到类似 scheduled__2016-09-20T00:00:00 的内容, 任务在 2016-09-21T00:00:00 处运行,根据 ETL 这似乎是合理的模型。

但是有一天我的 dag 由于未知原因没有被触发,所以我手动触发它,如果我在 2016-09-20T00:10:00 触发它,那么 TimeDeltaSensor 将等到 2016-09-21T00:15:00运行前。

这不是我想要的,我希望它在 2016-09-20T00:15:00 运行不是第二天,我试过了execution_date通过--conf '{"execution_date": "2016-09-20"}' , 但它不起作用。

我该如何处理这个问题?

$ airflow version
[2016-09-21 17:26:33,654] {__init__.py:36} INFO - Using executor LocalExecutor
  ____________       _____________
 ____    |__( )_________  __/__  /________      __
____  /| |_  /__  ___/_  /_ __  /_  __ \_ | /| / /
___  ___ |  / _  /   _  __/ _  / / /_/ /_ |/ |/ /
 _/_/  |_/_/  /_/    /_/    /_/  \____/____/|__/
   v1.7.1.3

最佳答案

首先,我建议您对 start_date 使用常量,因为根据调度程序评估的 Airflow 管道,动态的行为会不可预测。

关于 start_date 的更多信息在我写的 FAQ 条目中,将所有这些整理出来: https://airflow.apache.org/faq.html#what-s-the-deal-with-start-date

现在,关于 execution_date当它被触发时,这是使用 Airflow 的人的常见问题。 Airflow 套execution_date基于它所覆盖的计划周期的左边界,而不是基于它触发的时间(这将是该周期的右边界)。运行 schedule='@hourly' 时task 例如,一个任务将每小时触发一次。下午 2 点触发的任务将有一个 execution_date。下午 1 点,因为它假定您在下午 2 点处理下午 1 点到下午 2 点的时间窗口。同样,如果您运行日常作业,则运行 execution_date2016-01-01将在 2016-01-02 午夜后不久触发.

在考虑 ETL 和差异负载时,这种左边界标记很有意义,但在考虑简单的、类似 cron 的调度程序时会变得困惑。

关于python - airflow trigger_dag execution_date 是第二天,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39612488/

相关文章:

python pdb自动 pretty-print

airflow - 如何触发每日 DAG 在本地时间午夜而不是 UTC 时间午夜运行

docker - 使用 docker-compose 运行分布式 Airflow 架构时如何将新用户添加到 docker 镜像

python - Airflow + Kubernetes Executor 资源版本太旧

python - 运行时错误 : Attempting to deserialize object on CUDA device 2 but torch. cuda.device_count() 为 1

python - 如何使用多个选择选项并使这些选项保持选中状态?

python - Python中字符串的条件显示

python - 属性错误 : module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

mysql - 如何在 Airflow UI 中检查连接是否有效?

python - 无法在 GitHub 上安装 Python 库的最新候选版本