In my cloud code, I would like to update all of my record which is around 50k with a new data. But I noticed that my job fails even though I follow 1000 records limit. I get success/error was not called error for this job. Any Idea how can I resolve this?
Parse.Cloud.job("hello", function(request, response) {
Parse.Cloud.useMasterKey();
var results = [];
var limit = 1000;
var saveUpdatedQueries = function(queries) {
console.log("updating records " + queries.length);
Parse.Object.saveAll(queries,{
success:function(lists){
console.log("lists ok "+lists.length);
if (!results.length) {
response.success("finished");
return;
}
updatingRecords(lists.length);
},error: function(reason){
console.log("error");
}
});
}
var updatingRecords = function(skip) {
var tempRecords = [];
if (skip) {
results = results.slice(skip);
}
console.log("skip: " + skip + " Results length: "+ results.length);
for (var i = 0; i < results.length; i++) {
var today = new Date();
var newObject = results[i];
newObject.set('newCulumn', today);
tempRecords.push(newObject);
if (i === results.length - 1 || tempRecords.length === limit) {
break;
};
};
saveUpdatedQueries(tempRecords);
}
var processCallback = function(res) {
results = results.concat(res);
if (res.length === limit) {
process(res[res.length - 1].id);
return;
}
updatingRecords(0);
}
var process = function(skip) {
var query = new Parse.Query(Parse.Installation);
if (skip) {
query.greaterThan("objectId", skip);
}
query.limit(limit);
query.ascending("objectId");
query.find().then(function querySuccess(res) {
processCallback(res);
}, function queryFailed(reason) {
if (reason.code == 155 || reason.code == 141) { // exceeded parse timout
console.log("time out error");
process(skip);
} else {
response.error("query unsuccessful, length of result " + results.length + ", error:" + reason.code + " " + reason.message);
}
});
}
process(false);
});