Skip to content

Commit

Permalink
新增邮件补发功能
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaojun1998 committed May 30, 2019
1 parent faa7239 commit b1a84b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ AV.Cloud.afterSave('Comment', function (request) {
});
});

AV.Cloud.define('resend_mails', function(req) {
let query = new AV.Query(Comment);
query.greaterThanOrEqualTo('createdAt', new Date(new Date().getTime() - 24*60*60*1000));
query.notEqualTo('isNotified', true);
// 如果你的评论量很大,可以适当调高数量限制,最高1000
query.limit(200);
return query.find().then(function(results) {
new Promise((resolve, reject)=>{
count = results.length;
for (var i = 0; i < results.length; i++ ) {
sendNotification(results[i], req.meta.remoteAddress);
}
resolve(count);
}).then((count)=>{
console.log(`昨日${count}条未成功发送的通知邮件处理完毕!`);
}).catch(()=>{

});
});
});

AV.Cloud.define('self_wake', function(req) {
request(process.env.ADMIN_URL, function (error, response, body) {
console.log('自唤醒任务执行成功,响应状态码为:', response && response.statusCode);
Expand Down
4 changes: 4 additions & 0 deletions utilities/send-mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ exports.notice = (comment) => {
if (error) {
return console.log(error);
}
comment.set('isNotified', true);
comment.save();
console.log("收到一条评论, 已提醒站长");
});
}
Expand Down Expand Up @@ -89,6 +91,8 @@ exports.send = (currentComment, parentComment)=> {
if (error) {
return console.log(error);
}
currentComment.set('isNotified', true);
currentComment.save();
console.log(currentComment.get('nick') + " @了" + parentComment.get('nick') + ", 已通知.");
});
};
Expand Down

0 comments on commit b1a84b4

Please sign in to comment.