Brij Raj Singh - MSFT
Brij Raj Singh - MSFT

Reputation: 5113

Parse.com http response is not returned, and status is not defined

I am facing 2 issues with writing a background job in parse

Here is my code

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.");
  });   
});

The Issues I have are

  1. In the logs I frequently see this error

    Ran job createSilentUsers with: Input: {} Failed with: ReferenceError: status is not defined at main.js:74:9 at r (Parse.js:2:4981) at Parse.js:2:4531 at 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)

  2. The http request just doesn't seem to work, while it always does if I test it from some http REST client.

Upvotes: 3

Views: 1112

Answers (1)

user4933128
user4933128

Reputation: 21

Just change the "response" to "status" on the funcion header.

Parse.Cloud.job("createSilentUsers",function(request,response){

to this

Parse.Cloud.job("createSilentUsers",function(request,status){

Upvotes: 2

Related Questions