如何在本地配置 Firebase 函数的超时

How to configure timeout of Firebase functions on local

我想在 firebase 函数上做一些高强度的工作,通常需要 60 多秒。 在生产环境中,我可以从 Web 控制台设置更长的超时时间,但我找不到本地环境的设置。

以下是我用来开始服务的命令。

firebase serve --only functions

我正在使用 HTTPS 触发器,下面是在本地触发我的函数的命令。

functions-emulator call myfunc --data='{"uid":"user_id_1"}'

有没有办法在本地配置超时?

您可以将时间设置为 60 秒以上。

可以在此处更改默认超时: Console Cloud functions


select function -> name function -> edit -> timeout

您可以使用 RunWith 函数在本地设置超时和内存选项

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
});

timeoutSeconds 的最大值为 540,即 9 分钟。内存的有效值为:

128MB
256MB
512MB
1GB
2GB

我为此苦苦挣扎了一段时间,但最终找到了这个解决方案:

  • 在您的函数目录中,添加一个名为 .env.local
  • 的文件
  • 将这一行添加到该文件:FUNCTIONS_EMULATOR_TIMEOUT_SECONDS=540s
  • 执行函数的构建。
  • 关闭然后重新启动本地模拟器。应遵守此新 .env.local 文件中设置的超时。

h/t 到 volkyeth 以获取相关的 GitHub firebase 问题响应: https://github.com/firebase/firebase-tools/issues/2837#issuecomment-1048878134