Is there a job scheduler library for node.js? [closed]

空扰寡人 提交于 2019-11-26 06:56:23

问题


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?


回答1:


node-cron does just what I described




回答2:


node-schedule A cron-like and not-cron-like job scheduler for Node.




回答3:


agenda is a Lightweight job scheduling for node. This will help you.




回答4:


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




回答5:


I am using kue: https://github.com/learnboost/kue . It is pretty nice.

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.

Edit:

  1. kue is not a cron like library.
  2. By default kue does not supports job which runs repeatedly (e.g. every Sunday).



回答6:


node-crontab allows 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.




回答7:


You can use 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.

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)




回答8:


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,

Runnr.addIntervalJob('10:20', function(){...}, 'myjob')

To do a job at 10am and 3pm daily,

Runnr.addDailyJob(['10:0:0', '15:0:0'], function(){...}, 'myjob')

Its that simple. For further detail: https://github.com/Saquib764/node-runnr




回答9:


All these answers and noone has pointed to the most popular NPM package .. cron

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




回答10:


Both node-schedule and node-cron we can use to implement cron-based schedullers.

NOTE : for generating cron expressions , you can use this cron_maker




回答11:


This won't be suitable for everyone, but if your application is already setup to take commands via a socket, you can use netcat to issue a commands via cron proper.

echo 'mycommand' | nc -U /tmp/myapp.sock


来源:https://stackoverflow.com/questions/3785736/is-there-a-job-scheduler-library-for-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!