gpt4 book ai didi

javascript - 什么会导致 parse.com 云代码计数中出现 "Request timed out"?

转载 作者:行者123 更新时间:2023-11-30 00:33:26 25 4
gpt4 key购买 nike

我的一个云函数偶尔会超时。它似乎很难计数,尽管类(class)中只有大约 700 个对象。如果能提供有关如何调试此问题的任何提示,我将不胜感激。

云功能大部分时间都能正常工作。

记录的错误示例:

E2015-02-03T02:21:41.410Z] v199: Ran cloud function GetPlayerWorldLevelRank for user xl8YjQElLO with:
Input: {"levelID":60}
Failed with: PlayerWorldLevelRank first count error: Request timed out

下面的代码有什么看起来很奇怪的地方吗?超时错误通常在第二次计数(query3)中抛出,尽管有时它在第一次计数(query2)中超时。

Parse.Cloud.define("GetPlayerWorldLevelRank", function(request, response) {    
var query = new Parse.Query("LevelRecords");
query.equalTo("owner", request.user);
query.equalTo("levelID", request.params.levelID);
query.first().then(function(levelRecord) {
if (levelRecord === undefined) {
response.success(null);
}
// if player has a record, work out his ranking
else {
var query2 = new Parse.Query("LevelRecords");
query2.equalTo("levelID", request.params.levelID);
query2.lessThan("timeSeconds", levelRecord.get("timeSeconds"));
query2.count({
success: function(countOne) {
var numPlayersRankedHigher = countOne;

var query3 = new Parse.Query("LevelRecords");
query3.equalTo("levelID", request.params.levelID);
query3.equalTo("timeSeconds", levelRecord.get("timeSeconds"));
query3.lessThan("bestTimeUpdatedAt", levelRecord.get("bestTimeUpdatedAt"));
query3.count({
success: function(countTwo) {
numPlayersRankedHigher += countTwo;
var playerRanking = numPlayersRankedHigher + 1;
levelRecord.set("rank", playerRanking);
// The SDK doesn't allow an object that has been changed to be serialized into a response.
// This would disable the check and allow you to return the modified object.
levelRecord.dirty = function() { return false; };
response.success(levelRecord);
},
error: function(error) {
response.error("PlayerWorldLevelRank second count error: " + error.message);
}
});
},
error: function(error) {
response.error("PlayerWorldLevelRank first count error: " + error.message);
}
});
}
});
});

最佳答案

我认为问题不在您的代码中。就像错误消息指出的那样:请求超时。即Parse API在超时时间内没有响应或者网络导致超时。一旦您执行了 .count,一些 API 调用可能已完成,然后无法连接或超时。

显然有更多人有这个问题:https://www.parse.com/questions/ios-test-connectivity-to-parse-and-timeout-question .似乎不可能增加超时时间,因此这篇文章中的建议是:

For that reason, I suggest setting a NSTimer prior to executing the query, and invalidating it when the query returns. If the NSTimer fires before being invalidated, ask the user if they want to keep waiting for the results to come back, or show them a message indicating that the request is taking a long time to complete. This gives the user the chance to wait more if they know their current network conditions are not ideal.

如果您正在处理网络,尤其是在移动平台上,您需要为网络故障做好准备。所以就像帖子建议的那样:为用户提供重试的选项。

关于javascript - 什么会导致 parse.com 云代码计数中出现 "Request timed out"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28294084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com