javascript - Parse function time out management -


in parse cloud code there response time limit of 15s. we've been experiencing problems on requests depend on external service requests.

if have 4 promises, promise 1 & 2 create objects if request "runs out of time" on promise 3 need destroy whatever created on process. i'm cascading error handling in similar way following example:

var obj1, obj2, obj3; query.find().then(function() {     obj1 = new parse.object('anything');     return obj1.save(); }).then(function() {     obj2 = new parse.object('anything');     return obj2.save(); }).then(function _success() {     obj3 = new parse.object('anything');     return obj3.save(); }).then(function _success() {     response.success(); }, function _error(err) {    var errorpromises = [];    if (obj1 != undefined) errorpromises.push(deleteexternalstuff(obj1.id));    if (obj2 != undefined) errorpromises.push(deleteexternalstuff(obj2.id));    if (obj3 != undefined) errorpromises.push(deleteexternalstuff(obj3.id));     parse.promise.when(errorpromises).then(function _success() {         response.error();    }, function _error() {        response.error(err);    }); }); 

the deleteexternalstuff function makes get request on 1 of object's id , returns object.destroy() promise.

my problem get query works destroy promises inside deleteexternalstuff not deleting objects database. suggestions on how handle case?

edit:

i've tested , whenever timeout occurs, error indeed executed destroy() not working right.

edit 2: added similar structure deleteexternalstuff function

function deleteexternalstuff(objectid) {     var query = parse.query('another object');     query.equalto('objxxx', objectid);     return query.find().then(function _success(anotherbunchofobjects) {         var deletepromises = _.map(anotherbunchofobjects, function(obj) {             return obj.destroy();         });         return parse.promise.when(deletepromises);     }, function _error(error) {         console.log(error);           // **error log**         return parse.promise.as();     }); } 

edit 3:

with further testing added error handler in deleteexternalstuff function , printed log... apparently **error log** prints following: {"code":124,"message":"request timed out"}

this makes me think parse doesn't permit use of chained promises in error handling if have reached timeout limit... :\

suggestions alternate solutions appreciated.

to make sure objects deleted before request finished, have wait until promises resolved:

var promises = []; if (obj1 != undefined) promises.push(deleteexternalstuff(obj1.id)); if (obj2 != undefined) promises.push(deleteexternalstuff(obj2.id)); if (obj3 != undefined) promises.push(deleteexternalstuff(obj3.id)); promise.all(promises).then(function() {     response.error(err); }); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -