我在这里做错了,第一个API返回SKU的列表,在循环中查询以获取构建列表。有时他们确实正确地获得了所有构建列表,但大多数时候我都会收到此错误
请求的资源不可用。 Apache Tomcat / 7.0.64
我是否在这里发送API调用? API工作正常如果我直接查询它。
getVersionsForPlaytest: function (shiftTitleId, shiftPlatformId, email, callback) {
//console.log('getversions platform ', shiftPlatformId);
client.operation('GetSkusList')
.params({
'Platform ID': shiftPlatformId,
'Title ID': shiftTitleId,
'User': email
})
.headers(getHeaders(email))
.execute(function (err, skus) {
if (err) {
Log.error('Shift', 'Failed to get SKUs for "' + shiftTitleId + '"', {err});
callback(err);
} else {
if (skus.value.length) {
// console.log('getversions sku length - ', skus.value.length);
var promises = [];
var versions = [];
var i = 0;
var len = skus.value.length;
while (i < len) {
(function (sku) {
promises.push(function (callback) {
client.operation('GetBuildsList')
.params({
'SKU ID': sku['SKU ID'],
'Lifecycle Status': 'Available',
'Build Type': 'Playtest',
'User': email
})
.headers(getHeaders(email))
.execute(function (err, data) {
if (err) {
Log.error('Shift', 'Failed to get version for SKU "' + sku['SKU ID'] + '"', {err});
} else if (data.value.length) {
// console.log('getversions getbuildlist length - ', data.value.length);
versions = versions.concat(data.value);
//console.log('getversions getbuildlist - ', data.value);
}
callback();
});
});
})
(skus.value[i]);
i++;
}
async.parallel(promises, function () {
versions = versions.map(function (item) {
item.buildId = item['Build ID'];
return item;
});
callback(err, versions);
});
} else {
callback(err, []);
}
}
})
}
答案 0 :(得分:0)
使用async.series解决此问题。我的不好