fix(core): update

This commit is contained in:
Philipp Kunz 2020-07-12 00:25:55 +00:00
parent a1996ea1bd
commit 7c73579c9f

View File

@ -28,29 +28,36 @@ export class CronManager {
* starts the cronjob * starts the cronjob
*/ */
public start() { public start() {
this.status = 'started'; if (this.status !== 'started') {
for (const cronJob of this.cronjobs.getArray()) { this.status = 'started';
cronJob.start(); for (const cronJob of this.cronjobs.getArray()) {
} cronJob.start();
this.executionTimeout = new plugins.smartdelay.Timeout(0); }
this.executionTimeout = new plugins.smartdelay.Timeout(0);
// recursion // recursion
const runCheckExecution = () => { const runCheckExecution = () => {
console.log(`Next CronJob scheduled in ${this.executionTimeout.getTimeLeft()} milliseconds`); console.log(
this.executionTimeout.promise.then(() => { `Next CronJob scheduled in ${this.executionTimeout.getTimeLeft()} milliseconds`
let timeToNextOverallExecution: number; );
for (const cronJob of this.cronjobs.getArray()) { this.executionTimeout.promise.then(() => {
const timeToNextJobExecution = cronJob.checkExecution(); let timeToNextOverallExecution: number;
if (timeToNextJobExecution < timeToNextOverallExecution || !timeToNextOverallExecution) { for (const cronJob of this.cronjobs.getArray()) {
timeToNextOverallExecution = timeToNextJobExecution; const timeToNextJobExecution = cronJob.checkExecution();
if (
timeToNextJobExecution < timeToNextOverallExecution ||
!timeToNextOverallExecution
) {
timeToNextOverallExecution = timeToNextJobExecution;
}
} }
} this.executionTimeout = new plugins.smartdelay.Timeout(timeToNextOverallExecution);
this.executionTimeout = new plugins.smartdelay.Timeout(timeToNextOverallExecution); runCheckExecution();
runCheckExecution(); });
}); };
};
runCheckExecution(); runCheckExecution();
}
} }
/** /**