仅最新的操作员与气流中的追赶者之间的差异

问题描述 投票:1回答:1

正如标题所示,希望了解dag定义中catchup = False与最新的only运算符之间的区别。

https://airflow.apache.org/docs/stable/scheduler.htmlhttps://airflow.apache.org/docs/stable/_modules/airflow/operators/latest_only_operator.html

python airflow
1个回答
0
投票

嗯,我想它们是完全不同的概念,可以独立使用。的确可以同时使用它们来防止回填,但是如果您仅需担心,则只需使用catchup=False。实际上,其中一位Airflow开发人员引用了this reply,显然,好的做法是使用以下方法:

作为LatestOnlyOperator的作者,目标一直是权宜之计,直到catchup =错误着陆。

但是他继续说LatestOnlyOperator应该被弃用。我不同意(作为catchup=False and LatestOnlyOperator的用户),我将尽力解释。我对这两个概念的直觉是这样的:


Catchup = True

在DAG定义中(即,当您指定其default_args时,您可以将标志catchup设置为True。如果将此标志设置为True并将DAG设置为ON,则调度程序将为从start_date到“ present”的每个调度间隔创建DAG运行,并将顺序执行它们。引用documentation

如果dag.catchup值改为True,则调度程序将为2015-12-01和2016-01-02之间的每个完成间隔创建DAG运行(但对于2016-01-02而言尚未创建) ,因为该间隔尚未完成),调度程序将按顺序执行它们。


LatestOnlyOperator

A LatestOnlyOperatorBaseOperator的范围。如果DAG运行不在最新调度间隔(即“上次运行”)中,则用该操作员完成的任务将不会运行(即,将被跳过,并且还将跳过下游的任务)。也引用LatestOnlyOperator文档字符串:

"""
Allows a workflow to skip tasks that are not running during the most
recent schedule interval.

If the task is run outside of the latest schedule interval, all
directly downstream tasks will be skipped.

Note that downstream tasks are never skipped if the given DAG_Run is
marked as externally triggered.
"""

结论

您可以使用catchup=True定义计划的DAG,并使用LatestOnlyOperator确保在追赶运行期间某些任务不会执行。此外,如果您想重新运行一些过去的DAG运行(例如,通过在UI中清除它们),但是又有一些任务(例如发送通知),则可以使用LatestOnlyOperator

© www.soinside.com 2019 - 2024. All rights reserved.