diff --git a/src/job.ts b/src/job.ts index e89b1377..b1d8be75 100644 --- a/src/job.ts +++ b/src/job.ts @@ -16,15 +16,12 @@ export class CronJob { running = false; unrefTimeout = false; lastExecution: Date | null = null; + runOnce = false; context: CronContext; onComplete?: WithOnComplete extends true ? CronOnCompleteCallback : undefined; - get runOnce(): boolean { - return this.cronTime.realDate; - } - private _timeout?: NodeJS.Timeout; private _callbacks: CronCallback>[] = []; @@ -87,6 +84,10 @@ export class CronJob { ) as WithOnComplete extends true ? CronOnCompleteCallback : undefined; } + if (this.cronTime.realDate) { + this.runOnce = true; + } + this.addCallback(this._fnWrap(onTick)); if (runOnInit) { @@ -178,10 +179,12 @@ export class CronJob { if (!(time instanceof CronTime)) { throw new CronError('time must be an instance of CronTime.'); } + const wasRunning = this.running; this.stop(); this.cronTime = time; + if (time.realDate) this.runOnce = true; if (wasRunning) this.start(); } diff --git a/src/time.ts b/src/time.ts index 9814c630..3f4e74a3 100644 --- a/src/time.ts +++ b/src/time.ts @@ -84,7 +84,7 @@ export class CronTime { return date.weekday === 7 ? 0 : date.weekday; } - /* + /** * Ensure that the syntax parsed correctly and correct the specified values if needed. */ private _verifyParse() { @@ -762,7 +762,7 @@ export class CronTime { } }); - // * is a shortcut to [low-high] range for the field + // "*" is a shortcut to [low-high] range for the field value = value.replace(RE_WILDCARDS, `${low}-${high}`); // commas separate information, so split based on those