I have a node.js server accepting requests from a web page. Upon receiving a "START" request, I want to be able to spawn a timer that executes a task in the background every n seconds endlessly. Is this doable? and what would be a good example? A simple psudo-code is as below:
app.get("myindependenttasks/starttask/:userid"){
//start a simple timer to handle to userid
//continue to run the timers endlessly while
//while this call returns a "Task running" status
//to the user.
//Other users should be able to run their own tasks.
}
Are there any downsides if the number of user requests are around 1000 running tasks.
You can use setInterval for this (http://nodejs.org/api/timers.html), but I'd be hesitant to do this for 1000s of these.
Instead, you should run one setInterval, and run the tasks for all connected users in this task.
So, when a user hits "myindependenttasks/starttask/:userid", it gets added to the list of users to process, and in your periodic task you go through that list one by one.