Skip to content

Commit

Permalink
fix: revert runOnce breaking changes (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox authored Oct 29, 2023
1 parent 4cb466e commit 7cb53ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ export class CronJob<OC extends CronOnCompleteCommand | null = null, C = null> {
running = false;
unrefTimeout = false;
lastExecution: Date | null = null;
runOnce = false;
context: CronContext<C>;
onComplete?: WithOnComplete<OC> extends true
? CronOnCompleteCallback
: undefined;

get runOnce(): boolean {
return this.cronTime.realDate;
}

private _timeout?: NodeJS.Timeout;
private _callbacks: CronCallback<C, WithOnComplete<OC>>[] = [];

Expand Down Expand Up @@ -87,6 +84,10 @@ export class CronJob<OC extends CronOnCompleteCommand | null = null, C = null> {
) as WithOnComplete<OC> extends true ? CronOnCompleteCallback : undefined;
}

if (this.cronTime.realDate) {
this.runOnce = true;
}

this.addCallback(this._fnWrap(onTick));

if (runOnInit) {
Expand Down Expand Up @@ -178,10 +179,12 @@ export class CronJob<OC extends CronOnCompleteCommand | null = null, C = null> {
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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7cb53ec

Please sign in to comment.