fix(core): update

This commit is contained in:
2020-09-04 06:39:22 +00:00
parent a7a961c869
commit 457182a97a
2 changed files with 19 additions and 9 deletions

View File

@@ -21,18 +21,29 @@ export class CronJob {
*/
public checkExecution(): number {
if (this.nextExecutionUnix === 0) {
this.nextExecutionUnix = Date.now() + this.croner.msToNext();
this.getNextExecutionTime();
}
if (Date.now() > this.nextExecutionUnix) {
const maybePromise = this.jobFunction();
if (maybePromise instanceof Promise) {
maybePromise.catch(e => console.log(e));
}
this.nextExecutionUnix = Date.now() + this.croner.msToNext();
this.nextExecutionUnix = this.getNextExecutionTime();
}
return this.nextExecutionUnix;
}
public getNextExecutionTime() {
return this.nextExecutionUnix = Date.now() + this.getTimeToNextExecution();
}
/**
* gets the time to next execution
*/
public getTimeToNextExecution() {
return this.croner.msToNext();
}
public start() {
this.status = 'started';
}