new to parse in the last couple of days, and was wondering if anyone might know what my problem is. I'm trying to create a background job that retrieves a list of strings from an external server, then loops through that list, saving objects containing those strings with a could function. The server returns a list of 20 items, but only 9 objects are saved. Even odder, it seems that the function that would save the object isn't even being called for the i
Here is my code:
var MyObject = Parse.Object.extend("MyObject");
Parse.Cloud.job("getNew", function (request, status) {
// Set up to modify user data
Parse.Cloud.useMasterKey();
var newObjects;
Parse.Cloud.httpRequest({
url: 'myURL',
success: function (httpResponse) {
newObjects = httpResponse.data;
var arrayLength = newObject.length;
console.log('got ' + newObjects.length + ' new Objects');
for (var i = 0; i < arrayLength; i++) {
console.log('saving Object ' + newTopics[i]);
Parse.Cloud.run('saveObject', {
name: newObjects[i]
}, {
success: function (message) {
console.log(message);
},
error: function (error) {
console.log(error);
}
});
}
status.success("New Objects Added.");
},
error: function (httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
status.error('Request failed with response code ' + httpResponse.status);
}
});
});
Parse.Cloud.define("saveObject", function (request, response) {
var query = new Parse.Query("Review");
var name = request.params.name;
var object = new MyObject();
object.set("name", name);
object.set("nameLowerCase", name.toLowerCase());
console.log('saving the object ' + object.get("name"));
object.save(null).then(
function (object) {
response.success('New object created with objectId: ' + object.get("name"));
},
function (error) {
console.log('Failed to create new object, with error code: ' + error.message);
});
});
My log output for the job is showing that the saveObject function isn't even being called for the unsaved items, even though the console log statement on the line before the call to save object call for those items does get logged.
Thanks to anyone who reads this, I would really appreciate the help.