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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 13:41:08  来源:igfitidea点击:

Is there a job scheduler library for node.js?

schedulingnode.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 JtR

node-crondoes just what I described

node-cron就是我所描述的

回答by Unitech

node-scheduleA cron-like and not-cron-like job scheduler for Node.

node-schedule一个类似于 cron 和非 cron 的 Node 作业调度程序。

回答by Fizer Khan

agendais a Lightweight job scheduling for node. This will help you.

议程是节点的轻量级作业调度。这会帮助你。

回答by X?pplI'-I0llwlg'I -

later.jsis a pretty good JavaScript "scheduler" library. Can run on Node.js or in a web browser.

later.js是一个非常好的 JavaScript“调度程序”库。可以在 Node.js 或 Web 浏览器中运行。

回答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:

官方功能和我的评论:

  1. 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.
  2. job event and progress pubsub.
    • I don't understand it.
  3. 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.
  4. infinite scrolling
    • Sometimes not working. Have to refresh.
  5. UI progress indication
    • Good for the time-consuming jobs.
  6. job specific logging
    • Because they are delayed jobs, you should log useful info in the job and check later through UI.
  7. 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!
  8. optional retries
    • Nice.
  9. full-text search capabilities
    • Good.
  10. RESTful JSON API
    • Sound good, but I never use it.
  1. 延迟的工作。
    • 如果您想让作业在特定时间运行,请计算该时间和现在之间的毫秒数。调用 job.delay(milliseconds) (文档说分钟,这是错误的。)不要忘记添加“jobs.promote();” 当您初始化作业时。
  2. 工作事件和进度发布订阅。
    • 我不明白。
  3. 丰富的集成用户界面。
    • 很有用。您可以在集成 UI 中查看作业状态(完成、运行、延迟),无需编写任何代码。您可以在 UI 中删除旧记录。
  4. 无限滚动
    • 有时不工作。必须刷新。
  5. 界面进度指示
    • 适合耗时的工作。
  6. 作业特定的日志记录
    • 因为它们是延迟作业,所以您应该在作业中记录有用的信息,然后通过 UI 进行检查。
  7. 由 Redis 提供支持
    • 很有用。当您重新启动 node.js 应用程序时,所有作业记录仍然存在,并且计划的作业也会执行!
  8. 可选重试
    • 好的。
  9. 全文搜索功能
    • 好的。
  10. RESTful JSON API
    • 听起来不错,但我从不使用它。


Edit:

编辑:

  1. kue is not a cron like library.
  2. By default kue does not supports job which runs repeatedly (e.g. every Sunday).
  1. kue 不是像库一样的 cron。
  2. 默认情况下,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

https://www.npmjs.com/package/cron

https://www.npmjs.com/package/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