【发布时间】:2018-11-30 22:52:03
【问题描述】:
我在 Android 上使用 Firebase Cloud Functions 库,并使用 getHttpsCallable 调用云函数。
问题是函数需要10-15秒才能将结果返回给客户端,所以客户端抛出异常java.net.SocketTimeoutException: timeout。
代码
// Create the arguments to the callable function.
Map<String, Object> data = new HashMap<>();
data.put("info", info);
mFunctions.getHttpsCallable(function)
.call(data)
.continueWith(new Continuation<HttpsCallableResult, String>() {
@Override
public String then(@NonNull Task<HttpsCallableResult> task) {
// This continuation runs on either success or failure, but if the task
// has failed then getResult() will throw an Exception which will be
// propagated down.
if (task.isSuccessful()) {
String result = (String) task.getResult().getData();
Log.v(Constants.LOG_TAG, result);
return result;
} else {
// The condition never was true, always logs the exception.
Exception e = task.getException();
Log.e(Constants.LOG_TAG, "Failed to join multiplayer room.", e);
return null;
}
}
});
如何更改超时,以便客户端在抛出异常之前等待更多时间?
注意。我没有使用 OkHttp、Retrofit 或默认系统网络功能,我使用 Firebase Cloud Functions 库 (getHttpsCallable) 来调用该功能。
【问题讨论】:
-
不是真的,我的云功能运行良好,但需要很长时间(这也很好,因为我想要那个)但是客户端(Android 应用程序)抛出异常,而不是服务器,所以我想让客户端等待更多,直到服务器响应。
-
我认为超时时间为 10 秒,并且无法使用当前的 Firebase API 进行配置。建议你file a feature request。
-
也许您可以将您的云功能更改为 HTTPS 功能,然后您就可以完全控制如何从您的应用中调用它。
-
只是添加我的声音,是的,60 秒的超时将非常有用。考虑到其余的 60 秒超时,我发现这条 10 秒规则很奇怪。改变超时的方法会很好。我正在结合使用可调用函数,该函数写入特定节点,我可以在其中获取数据。
标签: java android firebase networking google-cloud-functions