英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论