Reputation: 220
I made a scheduled job by the following code:
const schedule = require('node-schedule');
scheduleAuto1A = schedule.scheduleJob(time, function(){
// do some
});
a user enter the cron job time and it have to work until the user cancel it.
but the problem is:
When i restart my app or reboot server, it destroy.
How can i make a scheduled job for ever?
Upvotes: 2
Views: 1562
Reputation: 117
You can use Crontab (native linux/unix program) utility to schedule your jobs. If you want to do it via node.js, you can use PM2 (simple and easy). Otherwise, you can create systemd script to start your program at startup.
https://unix.stackexchange.com/questions/47695/how-to-write-startup-script-for-systemd
Upvotes: 1
Reputation: 169051
I took the liberty of editing your phrasing, since you're indeed not talking about cron jobs but a scheduled job within your Node.js process.
You can either
cron
functionality to run that function in a stand-alone script at a schedule (arguably easiest)cron
functionality to start your script at boot (@reboot
) (with the caveat that you are then still in charge of making sure you start your service if it shuts down)Upvotes: 1