Reputation: 726
I am using node js cron job
package :
var schedule = require('node-schedule');
var j = schedule.scheduleJob('*/1 * * * *', function(){
console.log('The answer to life, the universe, and everything!');
});
Bear with me I have multiple questions :
Question 1 My Node App hosted in AWS, so do i need to run any cron function in AWS EC2 Instance ?
Question 2 The way I am using my cron job inside node js is correct or running inside the os is recommended and why ?
Question 3 Do I need to restart my job if am using node js cron job ?
Upvotes: 0
Views: 1774
Reputation: 6099
Question 1 My Node App hosted in AWS, so do i need to run any cron function in AWS EC2 Instance ?
There is No need to run in ec2 as well as code you can choose one based on interval.
Question 2 The way I am using my cron job inside node js is correct or running inside the os is recommended and why ?
Now as long as //run the code
is not a CPU-bound thing like cryptography, you can stick with One Node process, at least to start. Since you are requiring request I think you might be making an HTTP request, which is I/O, which means this will be fine.
For what it is worth it's just simpler to have One thing to install/launch/start/stop/upgrade/connect-a-debugger
than to deal with an app server as well as a separate cron-managed process.
Also It depends on how strictly you have to adhere to that minute interval and if your node script is doing anything else in the meantime.
Just executing once a minute via CRON is much more straightforward and in my opinion conforms more to the Unix Philosophy.
Question 3 Do I need to restart my job if am using node js cron job ?
If you build and run this in node, you will have to manage the lifecycle of the app and make sure it's running, recover from crashes, etc.
Thanks
Upvotes: 2