英文:
Can't set timeout longer than 30s for Google Cloud/App Engine tasks
问题
我正在使用Google App Engine/Cloud Tasks运行一个任务,使用的是Python 3.7,有些情况下可能需要几个小时才能完成。
因此,我正在尝试扩展任务的默认超时时长。
查阅Python CloudTasksClient库的文档,Python CloudTasksClient库的文档显示create_task
方法有一个timeout
参数,它是一个浮点数。但没有解释默认值是多少,单位是什么(例如秒、分钟),或者可以设置的最大值是多少。
我尝试将timeout
设置为86400(即24小时),但得到了以下错误:
请求截止日期为2023-05-25T11:49:43.227120541-07:00。截止日期不能超过30秒。
这对我来说没有意义 - 为什么任务的时间限制要少于30秒?根据文档中的这个链接,我们在标准环境中使用手动缩放,因此超时应该可以延长到最多24小时。
提前感谢您的帮助!
英文:
I have a task I am running with Google App Engine/Cloud Tasks (as documented here) which uses Python 3.7 and could in some cases take up to a few hours to complete.
As such, I am trying to extend the default timeout length for the task.
Consulting the documentation for the Python CloudTasksClient library, its shown that the create_task
method has a timeout
parameter which is a float. What's not explained is what the default value is, what unit (e.g. seconds, minutes) it is, or what the maximum it can be set to is.
I tried setting timeout
to 86400 (aka 24 hours) and got the following error:
The request deadline is 2023-05-25T11:49:43.227120541-07:00. The deadline cannot be more than 30s in the future.
This doesn't make any sense to me — why should a task be limited to taking longer than 30 seconds? We use manual scaling in the Standard environment, so according to this in the docs the timeout should be extendable up to 24 hours.
Thanks for the help in advance!
答案1
得分: 0
截止日期因不同的目标而异根据文档:
- 对于HTTP目标,它是30分钟。
- 对于AppEngine目标,它要么是60分钟(Flex)要么是24小时(Standard)。
所以现在取决于您的任务目标是什么。如果是HTTP,也许值30是正确的,但错误消息中的单位可能写错了(秒而不是分钟)?
请提供有关您的任务具体是什么样子的更多详细信息。
英文:
The deadline varies for different targets according to the docs:
- for HTTP target it's 30 minutes
- for AppEngine target it's either 60 mins (Flex) or 24 hours (Standard)
So now it depends what the target of your task is. If it's HTTP, maybe the value 30 is correct, but they got the units in the error message wrong (seconds instead of minutes)?
Please provide more details about what how does your task look exactly.
答案2
得分: 0
也许这会有所帮助
-
timeout.py
(google/api_core/timeout.py)中有以下一段代码:class TimeToDeadlineTimeout(object): """一个装饰器,根据离截止时间还有多少时间来减少基于RPC的超时设置。当首次为rpc调用此装饰器时,截止时间被计算为 ``now + initial_timeout``。 换句话说,这个装饰器以一系列递减的超时时间 t0 > t1 > t2 ... tn >= 0 的方式实现截止时间语义。 参数: timeout(可选[float]):要应用于包装函数的超时时间(以秒为单位)。如果为`None`,则预期目标函数永远不会超时。 """
-
根据上述内容,解决您的问题的一个可能方案(为您的长时间运行任务提供足够的时间来结束)是将超时的值设置为
None
。我使用了None
的值进行了测试,没有收到错误,即以下代码是成功的:client.create_task(parent=parent, task=task, timeout=None)
-
如果必须为超时提供一个值,似乎不能超过30秒(这是默认值,如在
timeout.py
中找到的_DEFAULT_MAXIMUM_TIMEOUT = 30.0 # seconds
)。
英文:
Maybe this will help
-
timeout.py
(google/api_core/timeout.py) has the following piece of codeclass TimeToDeadlineTimeout(object): """A decorator that decreases timeout set for an RPC based on how much time has left till its deadline. The deadline is calculated as ``now + initial_timeout`` when this decorator is first called for an rpc. In other words this decorator implements deadline semantics in terms of a sequence of decreasing timeouts t0 > t1 > t2 ... tn >= 0. Args: timeout (Optional[float]): the timeout (in seconds) to applied to the wrapped function. If `None`, the target function is expected to never timeout. """
-
From the above, a possible solution to your problem (providing enough time for your long running task to end) would be to supply a value of
None
to the timeout. I tested with a value of None and didn't receive an error i.e. the following code was successfulclient.create_task(parent=parent, task=task, timeout=None)
-
If you must provide a value for the timeout, it looks like it can't be more than 30 seconds (this is the default value as seen in
_DEFAULT_MAXIMUM_TIMEOUT = 30.0 # seconds
which can be found intimeout.py
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论