javascript - Parse Query.First Success / Error Callback intermittently not called -


i'm working on parse cloud code issue has been puzzling me couple of days.

i have function check if user has registered push notifications , hasn't disabled them afterwards. takes response object input, field name check pfuser pointer, , callback.

function shouldsendpushnotification(object, field, callback){ user = object.get(field); if(!user){     console.log("error: no user in object");     return; } console.log('user is:'); console.log(user);  userid = user.id; console.log('seeking push status user: ' +userid); console.log(object);  userquery = new parse.query(parse.user); userquery.equalto("objectid", userid);  console.log('user query:'); console.log(userquery); userquery.first ({     success: function(userretrieved)     {         console.log('successfully found user:');         console.log(userretrieved);          if(userretrieved.get("pushenabled") == false){             console.log('error: push not enabled user. aborting.');             callback(false);             return;         }          console.log("push enabled user. continuing.")         callback(true);         return;     },     error: function(error)     {         console.log('error: failed find user push check.');         callback(false);         return;     } }); } 

i call method 2 locations. in aftersave function "messages" class has pointer reference pfuser (user field), , custom cloud function loops through "reminder" class has pointer called "owner" pfuser.

the log output of aftersave method below (reverse chronological order):

i2016-04-25t08:09:07.716z] - new object created objectid: 3olbwjbmvw i2016-04-25t08:09:07.679z] - sent new message push notification channel: user_7le4egeknc message: new message recieved richi rich i2016-04-25t08:09:07.578z] - fetching clinic details id: 7kgcjmlheu i2016-04-25t08:09:07.577z] - attempting push channel: user_7le4egeknc i2016-04-25t08:09:07.576z] - push enabled user. continuing. i2016-04-25t08:09:07.575z] - {"address1":"123 sesame street","address2":"","addresspostcode":1234,"addressstate":"vic","addresssuburb":"port melbourne","clinic":{"__type":"pointer","classname":"clinic","objectid":"7kgcjmlheu"},"createdat":"2016-03-20t09:35:52.252z","email":"email@email.com","emailverified":false,"firstname":"steve","lastname":"forbes","phone":"0400000000","pushenabled":true,"updatedat":"2016-04-18t00:47:54.340z","username":"email@email.com","objectid":"7le4egeknc"} i2016-04-25t08:09:07.574z] - found user:  i2016-04-25t08:09:07.526z] - {"where":{"objectid":"7le4egeknc"}} i2016-04-25t08:09:07.525z] - user query:  i2016-04-25t08:09:07.524z] - {"clinic":{"__type":"pointer","classname":"clinic","objectid":"7kgcjmlheu"},"content":"<html><body><p style=\"font-family: serif; font-size: 26px;\">this test message parse</p></body></html>","createdat":"2016-04-25t08:09:07.518z","isunread":true,"title":"yo - test","updatedat":"2016-04-25t08:09:07.518z","user":{"__type":"pointer","classname":"_user","objectid":"7le4egeknc"},"objectid":"3olbwjbmvw"}  i2016-04-25t08:09:07.523z] - seeking push status user: 7le4egeknc i2016-04-25t08:09:07.522z] - {"objectid":"7le4egeknc"} i2016-04-25t08:09:07.521z] - user is: 

for cloud function:

i2016-04-25t08:09:53.838z] - {"where":{"objectid":"7le4egeknc"}} i2016-04-25t08:09:53.837z] - user query:  i2016-04-25t08:09:53.836z] - {"owner":{"__type":"pointer","classname":"_user","objectid":"7le4egeknc"},"createdat":"2016-04-10t05:45:26.552z","frequencyinterval":0,"name":"test","nextreminderdate":{"__type":"date","iso":"2016-04-26t06:45:00.000z"},"pet":"pizza","startdate":{"__type":"date","iso":"2016-04-12t06:45:14.000z"},"type":0,"updatedat":"2016-04-25t07:06:46.986z","objectid":"bgvpwnq5sb"}  i2016-04-25t08:09:53.835z] - seeking push status user: 7le4egeknc i2016-04-25t08:09:53.834z] - {"objectid":"7le4egeknc"} i2016-04-25t08:09:53.833z] - user is: 

as can see first call executes - second has identical input success/error callbacks on userquery.first() never executed. don't know why!

it helpful if include of functions referenced. stands, bit hard sure of 'big picture'.

my guess cloud code function not chaining promises. recommend adjusting function return promise instead of utilizing callback function.

what happening the cloud code function returning , not waiting around function complete, asynchronous. proper use of parse.promise resolve issue.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -