node.js 是否有作业调度程序库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3785736/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a job scheduler library for node.js?
提问by JtR
Is there some cron like library that would let me schedule some function to be ran at certain time (15:30 for example, not x hours from now etc)? If there isn't this kind of library how this should be implemented? Should I just set callback to be called every second and check the time and start jobs scheduled for the time or what?
是否有一些像库一样的 cron 可以让我安排一些功能在特定时间运行(例如 15:30,而不是从现在开始的 x 小时等)?如果没有这种库应该如何实现?我应该将回调设置为每秒调用一次并检查时间并启动为该时间安排的作业还是什么?
回答by Unitech
node-scheduleA cron-like and not-cron-like job scheduler for Node.
node-schedule一个类似于 cron 和非 cron 的 Node 作业调度程序。
回答by Fizer Khan
回答by X?pplI'-I0llwlg'I -
回答by Vince Yuan
I am using kue: https://github.com/learnboost/kue. It is pretty nice.
我正在使用 kue:https: //github.com/learnboost/kue。这很不错。
The official features and my comments:
官方功能和我的评论:
- delayed jobs.
- If you want to let the job run at a specific time, calculate the milliseconds between that time and now. Call job.delay(milliseconds) (The doc says minutes, which is wrong.) Don't forget to add "jobs.promote();" when you init jobs.
- job event and progress pubsub.
- I don't understand it.
- rich integrated UI.
- Very useful. You can check the job status (done, running, delayed) in integrated UI and don't need to write any code. And you can delete old records in UI.
- infinite scrolling
- Sometimes not working. Have to refresh.
- UI progress indication
- Good for the time-consuming jobs.
- job specific logging
- Because they are delayed jobs, you should log useful info in the job and check later through UI.
- powered by Redis
- Very useful. When you restart your node.js app, all job records are still there and the scheduled jobs will execute too!
- optional retries
- Nice.
- full-text search capabilities
- Good.
- RESTful JSON API
- Sound good, but I never use it.
- 延迟的工作。
- 如果您想让作业在特定时间运行,请计算该时间和现在之间的毫秒数。调用 job.delay(milliseconds) (文档说分钟,这是错误的。)不要忘记添加“jobs.promote();” 当您初始化作业时。
- 工作事件和进度发布订阅。
- 我不明白。
- 丰富的集成用户界面。
- 很有用。您可以在集成 UI 中查看作业状态(完成、运行、延迟),无需编写任何代码。您可以在 UI 中删除旧记录。
- 无限滚动
- 有时不工作。必须刷新。
- 界面进度指示
- 适合耗时的工作。
- 作业特定的日志记录
- 因为它们是延迟作业,所以您应该在作业中记录有用的信息,然后通过 UI 进行检查。
- 由 Redis 提供支持
- 很有用。当您重新启动 node.js 应用程序时,所有作业记录仍然存在,并且计划的作业也会执行!
- 可选重试
- 好的。
- 全文搜索功能
- 好的。
- RESTful JSON API
- 听起来不错,但我从不使用它。
Edit:
编辑:
- kue is not a cron like library.
- By default kue does not supports job which runs repeatedly (e.g. every Sunday).
- kue 不是像库一样的 cron。
- 默认情况下,kue 不支持重复运行的作业(例如每个星期天)。
回答by Blago
node-crontaballows you to edit system cron jobs from node.js. Using this library will allow you to run programs even after your main process termintates. Disclaimer: I'm the developer.
node-crontab允许您从 node.js 编辑系统 cron 作业。使用此库将允许您在主进程终止后运行程序。免责声明:我是开发人员。
回答by Simon Rigét
You can use timexe
你可以使用timexe
It's simple to use, light weight, has no dependencies, has an improved syntax over cron, with a resolution in milliseconds and works in the browser.
它使用简单,重量轻,没有依赖关系,比 cron 有改进的语法,以毫秒为单位的分辨率并在浏览器中工作。
Install:
安装:
npm install timexe
Use:
用:
var timexe = require('timexe');
var res = timexe("* * * 15 30", function(){ console.log("It's now 3:30 pm"); });
(I'm the author)
(我是作者)
回答by codedemon
I am the auhor of node-runnr. It have a very simple approach to create job. Also its very easy and clear to declare time and interval. For example, to execute a job at every 10min 20sec,
我是node-runnr 的作者。它有一个非常简单的方法来创建工作。声明时间和间隔也非常容易和清晰。例如,要每 10 分 20 秒执行一次作业,
Runnr.addIntervalJob('10:20', function(){...}, 'myjob')
To do a job at 10am and 3pm daily,
每天上午 10 点和下午 3 点工作,
Runnr.addDailyJob(['10:0:0', '15:0:0'], function(){...}, 'myjob')
Its that simple. For further detail: https://github.com/Saquib764/node-runnr
就这么简单。更多详情:https: //github.com/Saquib764/node-runnr
回答by danday74
All these answers and noone has pointed to the most popular NPM package .. cron
所有这些答案都没有人指出最受欢迎的 NPM 包 .. cron
回答by dush88c
Both node-scheduleand node-cronwe can use to implement cron-based schedullers.
这两个 节点的时间表和 节点的cron,我们可以用它来实现的cron为主schedullers。
NOTE: for generating cron expressions , you can use this cron_maker
注意:要生成 cron 表达式,您可以使用此cron_maker

