首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何为Apache Airflow DAG定义超时?

如何为Apache Airflow DAG定义超时?
EN

Stack Overflow用户
提问于 2019-07-19 18:49:06
回答 1查看 15K关注 0票数 10

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

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

代码语言:javascript
运行
复制
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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-19 21:51:55

source code中所述

代码语言:javascript
运行
复制
: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秒超时,如下所示:

代码语言:javascript
运行
复制
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)
票数 26
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57110885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档