Node-Cron保持Nodejs服务器忙碌
cron的工作
在我的mongodb集合中,每个文档与日期相关联, 我正在检查该日期是否通过并且该对象的状态处于活动状态,然后发送通知
cron.schedule('* * * * * *', () => {
collection.find()
.then((docs) => {
docs.forEach(async (doc) => {
// Check if date passed
let passed = checkIfToday(doc.date)
if(doc.status === "Active" && passed === true) {
// send Notification
activity(doc._id, "Reminder For status", "doc", [], doc._id, null, null, null)
}
});
})
});
,但是这种cron工作使我的服务器忙碌
cron执行完美,但 如果我提出任何对服务器的要求,它不响应
什么是最好的方法?
Working of Cron
In my mongoDB Collection Each document is associated with a date,
I'm checking if that date is passed and status of that object is Active then Send Notification
Like this
cron.schedule('* * * * * *', () => {
collection.find()
.then((docs) => {
docs.forEach(async (doc) => {
// Check if date passed
let passed = checkIfToday(doc.date)
if(doc.status === "Active" && passed === true) {
// send Notification
activity(doc._id, "Reminder For status", "doc", [], doc._id, null, null, null)
}
});
})
});
But This Cron Job keeping my server busy
Cron is executing perfectly but,
if I make any request to server its not responding
what is the best way to do it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论