From 7c73579c9faa2932ba487ddb189d14d29fcdee84 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 12 Jul 2020 00:25:55 +0000 Subject: [PATCH] fix(core): update --- ts/smarttime.classes.cronmanager.ts | 47 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/ts/smarttime.classes.cronmanager.ts b/ts/smarttime.classes.cronmanager.ts index 99a3850..f7ed75a 100644 --- a/ts/smarttime.classes.cronmanager.ts +++ b/ts/smarttime.classes.cronmanager.ts @@ -28,29 +28,36 @@ export class CronManager { * starts the cronjob */ public start() { - this.status = 'started'; - for (const cronJob of this.cronjobs.getArray()) { - cronJob.start(); - } - this.executionTimeout = new plugins.smartdelay.Timeout(0); + if (this.status !== 'started') { + this.status = 'started'; + for (const cronJob of this.cronjobs.getArray()) { + cronJob.start(); + } + this.executionTimeout = new plugins.smartdelay.Timeout(0); - // recursion - const runCheckExecution = () => { - console.log(`Next CronJob scheduled in ${this.executionTimeout.getTimeLeft()} milliseconds`); - this.executionTimeout.promise.then(() => { - let timeToNextOverallExecution: number; - for (const cronJob of this.cronjobs.getArray()) { - const timeToNextJobExecution = cronJob.checkExecution(); - if (timeToNextJobExecution < timeToNextOverallExecution || !timeToNextOverallExecution) { - timeToNextOverallExecution = timeToNextJobExecution; + // recursion + const runCheckExecution = () => { + console.log( + `Next CronJob scheduled in ${this.executionTimeout.getTimeLeft()} milliseconds` + ); + this.executionTimeout.promise.then(() => { + let timeToNextOverallExecution: number; + for (const cronJob of this.cronjobs.getArray()) { + const timeToNextJobExecution = cronJob.checkExecution(); + if ( + timeToNextJobExecution < timeToNextOverallExecution || + !timeToNextOverallExecution + ) { + timeToNextOverallExecution = timeToNextJobExecution; + } } - } - this.executionTimeout = new plugins.smartdelay.Timeout(timeToNextOverallExecution); - runCheckExecution(); - }); - }; + this.executionTimeout = new plugins.smartdelay.Timeout(timeToNextOverallExecution); + runCheckExecution(); + }); + }; - runCheckExecution(); + runCheckExecution(); + } } /**