Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert runOnce breaking changes #760

Merged
merged 5 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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