Im building a node.js script/app/process (new to node and its definitions) that should run at a certain hour (from a conf file) every day. Im using the Node Schedule package to schedule the main function to run at that appointed time everyday. But the thing is this package does an "in-process scheduling", which means my script must keep running in the background for the scheduling to work. So basically my code should look like this at the end:
- global consts initializing and dependencies (requires)
- job scheduling
- defining all functions necessary
- logic to make script run permanently.
This node.js app runs inside a docker on an ec2 machine in AWS. How can I accomplish the task of running it permanently? I need a programatic solution, something (a package, a design pattern) I can embed inside my code.
Might be important to note that inside my code I have only a few lines of "requires" and const initializations, and then 1 main function that invokes everything else, if it helps somehow. Also, because im using that Node Scheduler I mentioned, restarting the script when it ends (for example through docker if its possible) is a bad idea, because the scheduling job would be lost and the script itself does nothing except initializations and scheduling the main function to the desired time, so it would restart possibly every few milliseconds, which I guess is a bad practice.