我写了一个后台工作,如果他没有玩几个小时,就会向Android用户发送通知。虽然预定的作业工作正常并按我的意愿发送推送,但作业状态表示为“失败”脚本错误:'TypeError:无法调用方法'然后'未定义。
对此的任何帮助都会很棒。
这是后台工作的云代码:
var _ = require('underscore.js'); // Javascript library for _.each()
var moment = require('moment'); // Moments library to Convert UpdatedAt to Date
Parse.Cloud.job("PushNotificationWithTime", function(request, status) {
Parse.Cloud.useMasterKey();
var hoursPassed = request.params.hourspassed;
var currentDate = new Date();
var getCurrentTime = currentDate.getTime();
var currentDateInHours = Math.round(getCurrentTime / (1000 * 60 * 60));
var query2 = new Parse.Query(Parse.Installation);
query2.exists('currQuestion');
var query = new Parse.Query(Parse.Installation);
query.exists('currQuestion');
query.find({
success : function(results) {
_.each(results, function(result) {
var updatedAt = moment(result.updatedAt).toDate();
var userObjId = result.id;
var getUpdatedTime = updatedAt.getTime();
var updatedAtInHours = Math.round(getUpdatedTime/ (1000 * 60 * 60));
var differenceInHours = currentDateInHours - updatedAtInHours;
if (differenceInHours >= hoursPassed) {
query2.equalTo('objectId', userObjId);
var answer = result.get('currQuestion');
query2.equalTo('currQuestion', result.get('currQuestion'));
Parse.Push.send({
where : query2,
data : {
alert : "Answer :" + answer
}
}, {
success : function() {
status.success("Pushed!!");
},
error : function(error) {
status.error("Push.send() Error :" + error);
}
});
}
}).then(function() {
status.success("underscore.each success");
}, function(error) {
status.error("underscore.each Error:" + error);
});
},
error : function(error) {
status.error("Query Error :" + error);
}
});
});
感谢。