bluehalo / mean2-starter

Other
4 stars 0 forks source link

Scheduler Minimum Interval and Last Run #153

Open brianghig opened 6 years ago

brianghig commented 6 years ago

The scheduler service shows some inconsistent / unexpected behavior with scheduling. Perhaps this is simply my misunderstanding, but from what I'm seeing:

  1. the minimum interval (set globally in config.'scheduler.interval' with a default of 10s) disallows any scheduled services with an interval less than 10s because the global timeout only runs on this schedule
  2. the 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.
  3. the 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:

brianghig commented 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).