【问题标题】:Difference between latest only operator and catchup in AirflowAirflow 中最新的唯一运营商和追赶者之间的区别
【发布时间】:2020-04-16 14:16:57
【问题描述】:

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

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

【问题讨论】:

    标签: python airflow


    【解决方案1】:

    嗯,我想说,它们是完全不同的概念,它们可以独立使用。的确,它们都可以用来防止回填,但如果这是您唯一关心的问题,那么只需使用catchup=False。引用一位 Airflow 开发人员的 this reply 的话,事实上,使用它似乎很明显:

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

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


    追赶=真

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

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


    LatestOnlyOperator

    LatestOnlyOperatorBaseOperator 的扩展。如果 DAG 运行不在 最新的计划间隔 内(即“最后一次运行”),则使用此 Operator 执行的任务将不会运行(即会被跳过,也会跳过下游的任务)。同时引用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 .

    【讨论】:

      猜你喜欢
      • 2021-06-27
      • 2015-05-28
      • 2018-06-07
      • 1970-01-01
      • 2010-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-11
      相关资源
      最近更新 更多