2014-02-24 19 views
3

我現在面臨2個問題與寫入解析Parse.com HTTP響應不退還,不定義狀態

這裏後臺作業是我的代碼

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

我的問題是

  1. 在日誌中我經常看到這個錯誤

    冉工作createSilentUsers有: 輸入:{} 無法與:的ReferenceError:狀態沒有在main.js定義 :74:9 在r(Parse.js:2:4981) 在Parse.js:2:4531 在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. http請求似乎不起作用,但它總是會從一些http REST客戶端進行測試。

+0

我猜,這是此行是去錯了,因爲'status'是不確定的。 (「所有的用戶都被成功設置爲數據庫」);'(或者對於下面的錯誤發生時,你也使用'status')。 –

+0

是的,但「狀態」是解析後臺作業的必備內容,否則它不會在日誌中成功記錄,它也被稱爲樣本https://parse.com/docs/cloud_code_guide#jobs 「與其他雲功能,你應該處理成功和錯誤條件,對於後臺作業,你可以在函數完成時調用status.success()或status.error()來完成,然後你的作業執行狀態將被設置爲完成。你不會調用其中任何一種方法,你的工作將在15分鐘內超時。「 –

+1

確實如此,但他們使用'status'作爲他們對內部函數的第二個參數,你在那裏有'response'。所以在你的事業中它會是'response.success();' –

回答

2

只需在功能標題上將「響應」更改爲「狀態」即可。

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

這個

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

也有同樣的問題。這麼簡單,但仍需要數小時才能找到這個偉大的答案!謝謝! – Idan