如何在本地配置Firebase功能的超时

kas*_*iji 5 firebase firebase-tools

我想在firebase功能上做一些紧张的工作,通常需要60秒以上.在生产时,我可以从Web控制台设置超时,但我找不到本地环境的设置.

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

firebase serve --only functions

我正在使用HTTPS触发器,以下是在本地触发我的功能的命令.

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

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

Sut*_*onY 6

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

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

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


小智 3

您可以使用 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
});
Run Code Online (Sandbox Code Playgroud)

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

128MB
256MB
512MB
1GB
2GB