Open brianghig opened 6 years ago
It may be worth looking into implementing this with a third party library like https://github.com/agenda/agenda that would allow for persistence and multi-node support (e.g., only running a job on one node in a cluster by using MongoDB for locking support).
The
scheduler
service shows some inconsistent / unexpected behavior with scheduling. Perhaps this is simply my misunderstanding, but from what I'm seeing:timeoutHandler
checks if the current timestamp is greater than the lastRun + the serviceInterval. So, if a job last ran 10 seconds ago and is scheduled for 10 second intervals, it may not run until the next iteration.lastRun
value for each service is only set after the service completes. So, if a job is scheduled to run every 10 seconds, and takes 200ms to run, it would only run every 20 seconds.Proposed changes:
timeoutHandler
to the greatest common factor (so that a 10s interval doesn't artificially delay a 15s interval)lastRun
value to the timestamp when the service starts. (Note: we do not run the risk of concurrent executions because of the check on the boolean flag ofrunning
that is maintained for each service.)