每五分钟安排一次Node.js作业 [英] Schedule Node.js job every five minutes
本文介绍了每五分钟安排一次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屋!
查看全文