NodeJS server with a Mongo DB - one feature will generate a report JSON file from the DB, which can take a while (60 seconds up - has to process hundreds of thousands of entries).
We want to run this as a background task. We need to be able to start a report build process, monitor it, and abort it if the user decides to change the params and re build it.
What is the simplest approach with node? Don't really want to get into the realms of separate worker servers processing jobs, message queues etc - we need to keep this on the same box and fairly simple implementation.
1) Start the build as a async method, and return to the user, with socket.io reporting progress?
2) Spin off a child process for the build script?
3) Use something like https://www.npmjs.com/package/webworker-threads?
With the few approaches I've looked at I get stuck on the same two areas;
1) How to monitor progress? 2) How to abort an existing build process if the user re-submits data?
Any pointers would be greatly appreciated...
job
var - that holds on to a reference to the child, so you can stop it - but does it work on PID? PID get re used don't they? So the job we spawn might complete and its PID is freed up for any other new process to take? Which means job.kill() could potentially kill a different process if it works of PID alone? Or does it not work like that.... – Havildar