I have a background job as follows:
Parse.Cloud.job('checkProjectStatus', function(req, res) {
var Project = Parse.Object.extend('Project');
var projectQuery = new Parse.Query(Project);
projectQuery.find().then(function(projects) {
var promises = [];
for(var i = 0; i < projects.length; i++) {
var p = projects[i];
promises.push(
Parse.Cloud.httpRequest({
url: p.get('link').trim()
}).then(function(httpResponse) {
console.log(httpResponse.text);
p.set('status', httpResponse.status);
return p.save();
}, function(httpResponse) {
console.log('HTTP RESPONSE TEXT: ' + httpResponse.text);
p.set('status', httpResponse.status);
return p.save();
})
);
}
return Parse.Promise.when(promises);
}).then(function() {
res.success("DONE!");
});
});
The intended processing of the above background job is to fetch every object from Project class and make a httpRequest to the value of field "link" in it. Then save whatever response code is returned in the corresponding Project object. My code is just updating one object that too wrong. Can someone tell me what is wrong in the above code and guide me for a right code?