为 Firebase 的 Cloud Functions 设置超时不会保留在控制台中;这是一个错误吗?

问题描述 投票:0回答:5

更新:我更新了问题,以反映我在问题正文中描述的内容以及当时发生的情况。这也证明了为什么我没有将 Sanyam 的回答标记为正确。控制台中存在一个错误,导致超时值短暂。 @MichaelBleigh 的回复是最中肯的,让我知道问题何时解决。

我有一个云函数,在某些边缘情况下需要运行超过默认的 60 秒超时。

问题是,虽然可以在 Google Cloud 开发者控制台的 Cloud Functions 部分更改此值,但每次部署后它都会恢复为原始默认值。

有没有办法可以保留对此设置的更改,也许在 Firebase 配置文件之一中?

firebase firebase-realtime-database google-cloud-functions
5个回答
56
投票

可以在此处更改默认超时https://console.cloud.google.com/functions/list

select function
>
test function
>
edit
>
timeout


55
投票

开始 functions v2.0.0 您还可以在函数声明中设置超时,如文档中“设置超时和内存分配”部分中所述:

const runtimeOpts = {
  timeoutSeconds: 300,
  memory: '1GB'
}

exports.myStorageFunction = functions
  .runWith(runtimeOpts)
  .storage
  .object()
  .onFinalize((object) = > {
    // do some complicated things that take a lot of memory and time
  });

正如发行说明中还强调的那样:

您将需要 firebase-tools >=v4.0.0。

在 Mac 上,您可以使用以下命令获取最新的

firebase-tools

npm install -g firebase-tools

另请注意上面文档链接的限制和有效值:

The maximum value for timeoutSeconds is 540, or 9 minutes. 
Valid values for memory are:

128MB
256MB
512MB
1GB
2GB
4GB
8GB

4
投票

选择您的功能并按“编辑”后,它位于页面底部的“更多”下拉菜单下。当前最大值为 540 秒。


1
投票

根据@MichaelBleigh 的评论。最新版本的 Firebase CLI(本文发布时为 3.7.0)已解决此问题。

如果您仍然遇到此问题,请确保您使用的是最新版本的 Firebase CLI。


0
投票

如果您需要为 HTTP 云功能设置超时,您可以为 V2 生成这样做:

const runtimeOpts = {
  timeoutSeconds: 10,
};

export const httpGoogleGeminyWrapper = onRequest(runtimeOpts, async (req, res) => {

});

更多内容参见官方文档【通过HTTP请求调用函数

]1

© www.soinside.com 2019 - 2024. All rights reserved.