I have created a background job to run every minute. The purpose of it is to delete old or outdated data within the database. In this case, the user submits a time which has an attached timestamp to it, and the two values are stored in arrays times
and timestamp
. So I wrote my cloud code to check if the times are older than an hour via their timestamps. If so, delete them from the database. However, that's the part I'm having trouble with. Here's my cloud code so you can see what's going on:
Parse.Cloud.job("expireTimes", function(request, response){
Parse.Cloud.useMasterKey();
var currentTime = new Date().getTime() / 1000;
var query = new Parse.Query("Wait");
query.find().then(function(results) {
var times = (results.length>0)? results[0].get("times") : "n/a";
var timestamps = (results.length>0)? results[0].get("timestamp") : "n/a";
console.log("Got " + results.length + " Times: " + times);
console.log("Got " + results.length + " Timestamps: " + timestamps);
for (var i = 0; i < timestamps.length; i++) {
if (currentTime >= timestamps[i] + 3600) {
// Delete old wait times
timestamps.splice(i, 1);
times.splice(i, 1);
i--;
} else {
break;
}
};
response.success("success");
}, function(error) {
response.error(error);
});
})
How do I update the database and delete the values within the array. Because when a user submits the time, it just adds to the times
array. Well, if I have the background job going every minute, some entries aren't going to be over an hour old. I want to keep those, but get rid of the other ones.
Any ideas? Any help is much appreciated. Thank you