Is there a job scheduler library for node.js? [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this questionIs there some cron like library that would let me schedule some function to be ran at certain time (15:30 for example, n开发者_StackOverflow中文版ot 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?
node-cron does just what I described
node-schedule A cron-like and not-cron-like job scheduler for Node.
agenda is a Lightweight job scheduling for node. This will help you.
later.js is a pretty good JavaScript "scheduler" library. Can run on Node.js or in a web browser.
I am using kue: https://github.com/learnboost/kue . It is pretty nice.
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.
Edit:
- kue is not a cron like library.
- By default kue does not supports job which runs repeatedly (e.g. every Sunday).
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)
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.
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
All these answers and noone has pointed to the most popular NPM package .. cron
https://www.npmjs.com/package/cron
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
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
精彩评论