I ran into 2 problems when writing background work in parsing
Here is my code
Parse.Cloud.job("createSilentUsers",function(request,response){
Parse.Cloud.useMasterKey();
var query = new Parse.Query("biscootusers");
query.equalTo("isbiscootactivated",0);
query.equalTo("issnsactivated",0);
query.first({
success: function(result) {
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);
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
{
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() {
status.success("All the users been set to the db successfully");
}, function(error) {
status.error("Uh oh, something went wrong.");
});
});
I have problems
In magazines, I often see this error
Ran task createSilentUsers with: Input: {} Error: ReferenceError: status not defined on main.js: 74: 9 at r (Parse.js: 2: 4981) on Parse.js: 2: 4531 in Array.forEach (native) at Object.E.each.E.forEach [as_arrayEach] (Parse.js: 1: 666) at n.extend.resolve (Parse.js: 2: 4482) at null. (Parse.js: 2: 5061) at r (Parse.js: 2: 4981) at n.extend.then (Parse.js: 2: 5327) at r (Parse.js: 2: 5035)
The HTTP request just doesn't work, although it always works if I test it with some http REST client.
source
share