我在解析时编写后台作业面临2个问题
这是我的代码
Parse.Cloud.job("createSilentUsers",function(request,response){
// Set up to modify user data
Parse.Cloud.useMasterKey();
//get all the users from backupusers table where isbiscootactivated = 0 and issnsactivated=0
// Query for all users
var query = new Parse.Query("biscootusers");
query.equalTo("isbiscootactivated",0);
query.equalTo("issnsactivated",0);
query.first({
success: function(result) {
// Successfully retrieved the object.
var objUser = result;
console.log(result.attributes.deviceid);
console.log(result.attributes.imei);
console.log(result.attributes.appname);
console.log(result.attributes.appid);
console.log(result.attributes.appversion);
//check if the deviceid and imei set is already a biscoot activated user
var promise = Parse.Promise.as();
promise = promise.then(function() {
console.log("we are inside the prmise");
return Parse.Cloud.httpRequest({
method: 'POST',
url: 'http://<our server name>/1.0/PartnerActivation/isDeviceExists',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'},
body: {
imei: result.attributes.imei,
deviceid: result.attributes.deviceid,
appname: result.attributes.appname,
appid: result.attributes.appid,
appversion: result.attributes.appversion}
}).then(function(httpResponse)
{
console.log("Response of isdeviceactivated is " + httpResponse.text);
if(httpResponse.text == 'true' || httpResponse.text="True")
{
console.log("The user is already activated");
objUser.set("isbiscootactivated",1);
objUser.save();
}
else
{
//do the biscoot activation here
console.log("its not activated, lets do the biscootusers activation");
}
},
function(error) {
console.log("error occurred during isDeviceExists api as " + error);
});
});
console.log("nothing seems to have happened");
},
error: function(error) {
console.log("Error: " + error.code + " " + error.message);
}
}).then(function() {
// Set the job's success status
status.success("All the users been set to the db successfully");
}, function(error) {
// Set the job's error status
status.error("Uh oh, something went wrong.");
});
});
我遇到的问题
在日志中我经常看到此错误
Ran job createSilentUsers: 输入:{} 失败:引用错误:未定义状态 在main.js:74:9 在r(Parse.js:2:4981) 在Parse.js:2:4531 at Array.forEach(native) at Object.E.each.E.forEach [as _arrayEach](Parse.js:1:666) 在n.extend.resolve(Parse.js:2:4482) 在null。 (Parse.js:2:5061) 在r(Parse.js:2:4981) 在n.extend.then(Parse.js:2:5327) 在r(Parse.js:2:5035)
http请求似乎不起作用,如果我从某个http REST客户端测试它,它总是会这样做。
答案 0 :(得分:2)
只需更改&#34;响应&#34;到&#34;状态&#34;在funcion标题上。
Parse.Cloud.job("createSilentUsers",function(request,response){
到这个
Parse.Cloud.job("createSilentUsers",function(request,status){