如果Airflow任务运行时间超过10小时,有没有办法让任务失败?

huangapple go评论107阅读模式
英文:

Is there any way we can fail the task if it is running more than 10 hours in Airflow Dag

问题

在Airflow调度程序中,如果任务运行超过10个小时,任务应该被强制失败,并且在那时,Airflow进程应该触发警报并终止该任务。

我们是否有办法实现这个要求?请帮助我解决这个问题。

英文:

In Airflow scheduler, Task should forcefully fail if it is running more than 10 hours and at that point an alert should raised by the airflow process and terminating the job.

Is there any way we can achieve this. Please help me on this.

答案1

得分: 1

是的,你可以定义execution_timeout

execution_timeout的默认值是没有设置任何超时的任务。

你可以在特定操作符中覆盖这个值,例如:

from datetime import timedelta
op = MyOperator(
    ...
    execution_timeout=timedelta(VALUE),
)

例如:

op = BashOperator(
    task_id="my_task",
    execution_timeout=timedelta(days=2),
    bash_command="python my_script.py",
)

从Airflow版本2.3.0开始,你还可以使用AIRFLOW__CORE__DEFAULT_TASK_EXECUTION_TIMEOUT来全局设置它。

英文:

Yes, you can define execution_timeout.
The default value of execution_timeout is tasks not having any timeout set.

You can override the value in specific operator by

    from datetime import timedelta
    op = MyOperator(
        ...
        execution_timeout=timedelta(VALUE),
    )

for example:

    op = BashOperator(
        task_id="my_task",
        execution_timeout=timedelta(days=2),
        bash_command="python my_script.py",
    )

Starting Airflow>=2.3.0 you can also set it globally with
AIRFLOW__CORE__DEFAULT_TASK_EXECUTION_TIMEOUT

huangapple
  • 本文由 发表于 2023年6月22日 16:34:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76529990.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定