fix(core): update
This commit is contained in:
@ -1,17 +1,17 @@
|
||||
import * as plugins from './smarttime.plugins';
|
||||
import { CronManager } from './smarttime.classes.cronmanager';
|
||||
|
||||
export type TJobFunction = (() => void) | (() => Promise<any>);
|
||||
export type TJobFunction = (() => void) | (() => Promise<any>);
|
||||
|
||||
export class CronJob {
|
||||
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
||||
public cronExpression: string;
|
||||
public jobFunction: TJobFunction;
|
||||
|
||||
private cronInterval= plugins.cronParser.parseExpression('* * * * * *');
|
||||
|
||||
private cronInterval = plugins.cronParser.parseExpression('* * * * * *');
|
||||
private nextExecutionUnix: number = 0;
|
||||
|
||||
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction ) {
|
||||
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction) {
|
||||
this.cronExpression = cronExpressionArg;
|
||||
this.jobFunction = jobFunction;
|
||||
}
|
||||
@ -21,12 +21,18 @@ export class CronJob {
|
||||
*/
|
||||
public checkExecution() {
|
||||
if (this.nextExecutionUnix === 0) {
|
||||
this.nextExecutionUnix = this.cronInterval.next().toDate().getTime();
|
||||
this.nextExecutionUnix = this.cronInterval
|
||||
.next()
|
||||
.toDate()
|
||||
.getTime();
|
||||
return;
|
||||
}
|
||||
if (Date.now() > this.nextExecutionUnix) {
|
||||
this.jobFunction();
|
||||
this.nextExecutionUnix = this.cronInterval.next().toDate().getTime();
|
||||
this.nextExecutionUnix = this.cronInterval
|
||||
.next()
|
||||
.toDate()
|
||||
.getTime();
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +45,7 @@ export class CronJob {
|
||||
this.status = 'stopped';
|
||||
}
|
||||
|
||||
private getCronInterval () {
|
||||
private getCronInterval() {
|
||||
return plugins.cronParser.parseExpression(this.cronExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,6 @@ export class ExtendedDate extends Date {
|
||||
// INSTANCE
|
||||
public timezone: TAvailableZone;
|
||||
|
||||
|
||||
constructor(unixMilli: number) {
|
||||
super(unixMilli);
|
||||
}
|
||||
@ -116,10 +115,10 @@ export class ExtendedDate extends Date {
|
||||
year: this.getFullYear(),
|
||||
yearString: `${this.getFullYear()}`,
|
||||
month: this.getMonth() + 1,
|
||||
monthString: ("0" + (this.getMonth() + 1)).slice(-2),
|
||||
monthString: ('0' + (this.getMonth() + 1)).slice(-2),
|
||||
monthName: monthsArray[this.getMonth()],
|
||||
day: this.getDate(),
|
||||
dayString: ("0" + this.getDate()).slice(-2),
|
||||
dayString: ('0' + this.getDate()).slice(-2),
|
||||
dayOfTheWeek: this.getDay(),
|
||||
dayOfTheWeekName: daysArray[this.getDay()]
|
||||
};
|
||||
|
@ -3,7 +3,7 @@ import * as plugins from './smarttime.plugins';
|
||||
export class Interval {
|
||||
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
||||
private statusAuthorization: any = null;
|
||||
|
||||
|
||||
public intervalMilliseconds: number;
|
||||
public intervalJobs: Array<() => any> = [];
|
||||
constructor(intervalMillisencondsArg: number) {
|
||||
@ -23,7 +23,7 @@ export class Interval {
|
||||
runInterval();
|
||||
}
|
||||
|
||||
public stop () {
|
||||
public stop() {
|
||||
this.status = 'stopped';
|
||||
this.statusAuthorization = null;
|
||||
}
|
||||
@ -32,9 +32,9 @@ export class Interval {
|
||||
this.intervalJobs.push(funcArg);
|
||||
}
|
||||
|
||||
private executeIntervalJobs () {
|
||||
private executeIntervalJobs() {
|
||||
for (const funcArg of this.intervalJobs) {
|
||||
funcArg();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user