node.js - Is it more efficient to run a Node JS application through CRON at set times, or to run a 24/7 Node Application utilizing CRON inherently? -


is more efficient run node js application through cron @ set times, or run 24/7 node application utilizing schedulers inherently?

option a:

  • cron job daily process - calls daily nodejs app
  • cron job weekly process - calls weekly nodejs app
  • advantage application runs when needs to.
  • disadvantage overhead , organization. required have separate projects/scripts each different action.

option b:

  • separate nodejs application runs 24/7.
  • calls it's daily operations daily, weekly operations weekly, etc.
  • advantage: 1 project containing cron rules - easy add more tasks
  • disadvantage: project must running 24/7, more overhead when not needed.

if looking @ daily , weekly frequency only, go cron job calls nodejs app. if task runs in 5 minutes, have cpu , ram utilisation during minutes, instead of having full nodejs app staying in memory , using cpu resources day (although minimal).

you don't need 2 directories; can have 1 directory have daily.js job file , weekly.js file. or have 1 single file (index.js) , call argument trigger daily or weekly job. in index.js need read process.argv array read argument passed in.

the index.js code follows:

if (process.argv[2] == "d") {    //code daily task  } else if (process.argv[2] == "w") {    //code weekly task  } else {    throw new error("invalid argument");  } 

and crontab file (to run daily job @ 3am every day , weekly job @ 6am on monday example):

0 3 * * * node /path/index.js d 0 6 * * 1 node /path/index.js w 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -