Skip to content

Commit

Permalink
Unified addJob method
Browse files Browse the repository at this point in the history
Allows to add the new job of any type to the scheduler
  • Loading branch information
jakmaz committed Apr 16, 2024
1 parent 37f5be1 commit 41a150b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/toadScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export class ToadScheduler {
this.jobRegistry = {}
}

/**
* @deprecated in favor of unified addJob method
*/
addIntervalJob(job: SimpleIntervalJob | LongIntervalJob) {
if (!this.engines.simpleIntervalEngine) {
this.engines.simpleIntervalEngine = new SimpleIntervalEngine()
Expand All @@ -28,10 +31,16 @@ export class ToadScheduler {
this.engines.simpleIntervalEngine.add(job)
}

/**
* @deprecated in favor of unified addJob method
*/
addLongIntervalJob(job: LongIntervalJob): void {
return this.addIntervalJob(job)
}

/**
* @deprecated in favor of unified addJob method
*/
addSimpleIntervalJob(job: SimpleIntervalJob): void {
return this.addIntervalJob(job)
}
Expand All @@ -45,6 +54,9 @@ export class ToadScheduler {
}
}

/**
* @deprecated in favor of unified addJob method
*/
addCronJob(job: CronJob): void {
if (!this.engines.cronJobEngine) {
this.engines.cronJobEngine = new CronJobEngine()
Expand All @@ -54,6 +66,16 @@ export class ToadScheduler {
this.engines.cronJobEngine.add(job)
}

addJob(job: Job): void {
if (job instanceof SimpleIntervalJob || job instanceof LongIntervalJob) {
this.addIntervalJob(job)
} else if (job instanceof CronJob) {
this.addCronJob(job)
} else {
throw new Error('Unsupported job type.')
}
}

stop(): void {
for (const engine of Object.values(this.engines)) {
engine?.stop()
Expand Down

0 comments on commit 41a150b

Please sign in to comment.