Node-Cron保持Nodejs服务器忙碌

发布于 2025-02-05 22:10:15 字数 697 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文