I’m not really looking for an answer - unless the answer is “here is a library that already does it” or “here is someone who tried it and all the reasons it cannot work”.
The operating system scheduler is irelevant here - unless I’m totally misunderstanding how node works, everything runs in a single process. Not just one process but a single thread - so given that pretty much the only thing running on my server is Meteor, the operating system scheduler isn’t useful here. Feel free to correct me on this - it would be a massive weight off my shoulders, but I’m about 99% sure I’m correct.
“Yield if it needs to” means exactly that - yield only if some condition is met - if you look at your example, the condition is trivial, yield every 1000 jobs, and resume as soon as the DB update is complete (a couple of ms later? Less?) - let’s ignore the load that would add to the oplog and mongo DB 1000000 unnecessary updates every 30 seconds, yikes.
“resume when the server has capacity” also means exactly that - when the CPU usage of the server drops below a certain threshold, resume - this way when the server is idle the job runs as fast as it can, when the server is busy, the job runs more slowly - but the server is still responsive. The purpose of this is not for REALLY long running jobs that should run in their own process, but jobs that take 2-3 seconds, one or two users running that job, no big deal, 20 or 30 users running that job… This is a bigger problem, but potentially not worth spinning up a new server, or new process to handle.
It is not just CPU usage I am interested in - DB calls is another metric of interest, throttling DDP invocations only goes so far, depending on the arguments issued a DDP call could return 1, 50, 5000 documents, it could return just 1, but require 50 or 1000 documents to get the information required by the one.
“If you want to like, idle more” - yes, I do, but I want to Idle more by an amount that changes, based on usage, using values that I don’t want to rewrite/redefine in every function where I want to use it - one option here is abstracting this type of functionality to a package…