【问题标题】:How to define a timeout for Apache Airflow DAGs?如何为 Apache Airflow DAG 定义超时?
【发布时间】:2019-07-19 10:49:05
【问题描述】:

我使用的是 Airflow 1.10.2,但 Airflow 似乎忽略了我为 DAG 设置的超时。

我正在使用 dagrun_timeout 参数(例如 20 秒)为 DAG 设置超时期限,并且我有一个需要 2 分钟才能运行的任务,但 Airflow 将 DAG 标记为成功!

args = {
    'owner': 'me',
    'start_date': airflow.utils.dates.days_ago(2),
    'provide_context': True,
}

dag = DAG(
    'test_timeout',
     schedule_interval=None,
     default_args=args,
     dagrun_timeout=timedelta(seconds=20),
)

def this_passes(**kwargs):
    return

def this_passes_with_delay(**kwargs):
    time.sleep(120)
    return

would_succeed = PythonOperator(
    task_id='would_succeed',
    dag=dag,
    python_callable=this_passes,
    email=to,
)

would_succeed_with_delay = PythonOperator(
    task_id='would_succeed_with_delay',
    dag=dag,
    python_callable=this_passes_with_delay,
    email=to,
)

would_succeed >> would_succeed_with_delay

不会抛出任何错误消息。我是否使用了错误的参数?

【问题讨论】:

    标签: airflow


    【解决方案1】:

    source code中所述:

    :param dagrun_timeout: specify how long a DagRun should be up before
        timing out / failing, so that new DagRuns can be created. The timeout
        is only enforced for scheduled DagRuns, and only once the
        # of active DagRuns == max_active_runs.
    

    所以这可能是您设置schedule_interval=None 时的预期行为。这里的想法是确保计划的 DAG 不会永远持续并阻止后续运行实例。

    现在,您可能对所有运算符中可用的execution_timeout 感兴趣。 例如,您可以像这样在 PythonOperator 上设置 60 秒超时:

    would_succeed_with_delay = PythonOperator(task_id='would_succeed_with_delay',
                                dag=dag,
                                execution_timeout=timedelta(seconds=60),
                                python_callable=this_passes_with_delay,
                                email=to)
    

    【讨论】:

    • 谢谢你,卢卡斯。我现在就试试。
    • 答案写得很好,+1,但我认为您将“execution_timeout”拼错为“execution_timout”。我正在寻找 execution_timeout 变量,所以你帮了我,先生
    猜你喜欢
    • 1970-01-01
    • 2017-12-26
    • 2018-05-13
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    • 2018-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多