气流DAG的任务超时

时间:2019-06-18 11:37:18

标签: airflow airflow-scheduler

我在气流DAG中正在运行5个PythonOperator任务,其中之一正在执行ETL作业,这需要很长时间,因此所有资源都被阻塞了。有没有一种方法可以设置每个任务的最大执行时间,之后该任务要么失败,要么被标记为成功(以便DAG不会失败)并显示一条消息?

2 个答案:

答案 0 :(得分:2)

在每个运算符中,我们都有一个execution_timeout变量,您必须在其中传递一个datetime.timedelta对象。

根据base operator code comments

:param execution_timeout: max time allowed for the execution of
    this task instance, if it goes beyond it will raise and fail.
:type execution_timeout: datetime.timedelta

还要记住,这将使DAG一次运行失败并触发重新运行,并且仅在所有重新运行都失败后才被声明为失败的DAG。

因此,根据您分配的自动重试次数,您可能有( number of retries ) x ( timeout )的最大可能时间,以防代码花费太长时间。

答案 1 :(得分:0)

签出this previous answer.

简而言之,使用内置的pools气流甚至为任务(而不是整个DAG)指定start_date似乎是潜在的解决方案。