简体   繁体   English

Firebase Android云功能更改超时

[英]Firebase Android Cloud Functions Change Timeout

I'm using Firebase Cloud Functions library on Android and using getHttpsCallable to call a cloud function. 我在Android上使用Firebase Cloud Functions库并使用getHttpsCallable来调用云功能。

The problem is that the function needs 15-20 seconds to return the result back to the client, so the client throws an exception java.net.SocketTimeoutException: timeout. 问题是该函数需要15-20秒才能将结果返回给客户端,因此客户端抛出异常java.net.SocketTimeoutException: timeout.

Is there any way to change the timeout? 有没有办法改变超时?

There is currently no way to change the timeout on the client. 目前无法更改客户端上的超时。 The team is aware that this is a problem for some cases. 团队意识到这在某些情况下是个问题。 Until this becomes configurable, you have two options, your best option is write a regular HTTP function, and use your own HTTP client library that does allow configuring a timeout. 在此变为可配置之前,您有两个选项,最佳选择是编写常规HTTP函数,并使用您自己的HTTP客户端库,它允许配置超时。

You can file a feature request to add your voice. 您可以提交功能请求以添加语音。

The most recent version of the SDK adds setTimeout and withTimeout methods that let you configure a custom timeout. 最新版本的SDK添加了setTimeoutwithTimeout方法,可用于配置自定义超时。

See the docs here: https://firebase.google.com/docs/reference/android/com/google/firebase/functions/HttpsCallableReference 请参阅此处的文档: https//firebase.google.com/docs/reference/android/com/google/firebase/functions/HttpsCallableReference

Release Notes: https://firebase.google.com/support/release-notes/android 发行说明: https//firebase.google.com/support/release-notes/android

Seems like the article below is update on 25, Oct. So they probably added this feature by then. 似乎下面的文章是10月25日更新,所以他们可能在那时添加了这个功能。 Not sure if it have been before. 不确定它是否曾经存在过。

As the article said, we can now describe both timeout and memory: 正如文章所说,我们现在可以描述超时和内存:

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

Or, editing it directly via the Google Cloud Platform Console: 或者,直接通过Google Cloud Platform Console进行编辑:

  1. In the Google Cloud Platform Console, select Cloud Functions from the left menu. 在Google Cloud Platform Console中,从左侧菜单中选择“ 云功能 ”。
  2. Select a function by clicking on its name in the functions list. 通过单击功能列表中的名称来选择功能。
  3. Click the Edit icon in the top menu. 单击顶部菜单中的“ 编辑”图标。
  4. Select a memory allocation from the drop-down menu labeled Memory allocated . 从标记为已分配的下拉菜单中选择内存分配
  5. Click More to display the advanced options, and enter a number of seconds in the Timeout text box. 单击“ 更多”以显示高级选项,并在“ 超时”文本框中输入秒数。
  6. Click Save to update the function. 单击“ 保存”以更新该功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM