每五分钟安排一次 Node.js 作业 [英] Schedule Node.js job every five minutes

查看:17
本文介绍了每五分钟安排一次 Node.js 作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 node.js 的新手.我需要 node.js 每五分钟查询一个 mongodb,获取特定数据,然后使用 socket.io,允许订阅的 Web 客户端访问这些数据.我已经设置了 socket.io 部分,当然还有 mongo,我只需要知道如何让 node.js 每五分钟运行一次,然后发布到 socket.io.

I'm new to node.js. I need node.js to query a mongodb every five mins, get specific data, then using socket.io, allow subscribed web clients to access this data. I already have the socket.io part set up and of course mongo, I just need to know how to have node.js run every five minutes then post to socket.io.

对此的最佳解决方案是什么?

What's the best solution for this?

谢谢

推荐答案

var minutes = 5, the_interval = minutes * 60 * 1000;
setInterval(function() {
  console.log("I am doing my 5 minutes check");
  // do your stuff here
}, the_interval);

将该代码保存为 node_regular_job.js 并运行它:)

Save that code as node_regular_job.js and run it :)

这篇关于每五分钟安排一次 Node.js 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆