我写了一个后台作业,如果他几个小时没有玩,它会向 android 用户推送通知。尽管计划的作业工作正常并按我的意图发送推送,但作业状态状态为“失败”脚本错误:'TypeError:无法调用未定义的方法'then'。
对此的任何帮助都会很棒。
这是我用于后台作业的云代码:
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);
}
});
});
谢谢。