I'm not sure what's going wrong here / how I can fix it.
Parse.Cloud.job("expireTimes", function(request, response) {
var currentTime = new Date().getTime() / 1000;
var Wait = Parse.Object.extend("Wait");
Parse.Object.registerSubclass("Wait", Wait);
var query = new Parse.Query(Wait);
query.select(["times", "timestamp"]);
query.find({
success: function(results) {
for (var i = 0; i < timestamps.length; i++) {
if (currentTime >= timestamps[i] + 60) {
// Delete old wait times
timestamps.splice(i, 1);
times.splice(i, 1);
i--;
} else {
break;
}
};
response.success("Got " + results.length + " Query results: " + results[0].objectId);
},
error: function(error) {
response.error("Request failed with response code");
console.error("Request failed with response code ");
}
});
});
It tell's me that timestamps is undefined:
I2015-11-27T17:00:03.419Z]Deployed v17 with triggers:
Jobs:
expireTimes
E2015-11-27T17:01:04.489Z]v17 Ran job expireTimes with:
Input: {}
Result: ReferenceError: timestamps is not defined
at e.query.find.success (main.js:9:24)
at e.<anonymous> (Parse.js:14:28224)
at e.s (Parse.js:14:27156)
at e.n.value (Parse.js:14:26575)
at e.s (Parse.js:14:27284)
at e.n.value (Parse.js:14:26575)
at e.s (Parse.js:14:27284)
at e.n.value (Parse.js:14:26575)
at e.<anonymous> (Parse.js:14:27228)
at e.s (Parse.js:14:27156)
Not sure what this means / how to fix it. I would assume declare timestamps, but I thought that was already done with the retrieval of the arrays in the columns "times" and "timestamp"
Any help would be much appreciated. Thank you
There's no such idea as query.select()
. The only defined variables within the completion function are results (the array of retrieved parse objects) and currentTime, which you define in the enclosing scope.
The registerSubclass
isn't useful unless you're actually defining a subclass.
As a starting exercise, try querying the class and logging the results. The query can be as simple as:
var query = new Parse.Query("Wait");
query.find().then(function(results) {
console.log(JSON.stringify(results));
var firstId = (results.length>0)? results[0].id : "n/a"; // notice "id", not "objectId"
console.log("Got " + results.length + " First id: " + firstId);
response.success(results);
}, function(error) {
response.error(error); // return the real error so we can look at it
});
If timestamp
is a defined attribute on your Wait class, you can get it with get()...
// just like before where you got the id, try "getting" an attribute
var firstTimestamp = (results.length>0)? results[0].get("timestamp") : "n/a";
// remember, this depends on you defining a "timestamp" attribute on the class