Skip to content

Commit

Permalink
Merge pull request #1281 from d-lukutin/fix-cron-disabled-flag
Browse files Browse the repository at this point in the history
Fix cron disabled flag
  • Loading branch information
kamilmysliwiec committed May 17, 2023
2 parents 86c4c9d + 5d21e7f commit 726cc8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 6 additions & 6 deletions lib/scheduler.orchestrator.ts
Expand Up @@ -67,11 +67,6 @@ export class SchedulerOrchestrator
const cronKeys = Object.keys(this.cronJobs);
cronKeys.forEach((key) => {
const { options, target } = this.cronJobs[key];

if (options.disabled) {
return;
}

const cronJob = new CronJob(
options.cronTime,
target as any,
Expand All @@ -83,7 +78,12 @@ export class SchedulerOrchestrator
options.utcOffset,
options.unrefTimeout,
);
cronJob.start();

if (options.disabled) {
cronJob.stop();
} else {
cronJob.start();
}

this.cronJobs[key].ref = cronJob;
this.schedulerRegistry.addCronJob(key, cronJob);
Expand Down
4 changes: 1 addition & 3 deletions tests/e2e/cron-jobs.spec.ts
Expand Up @@ -115,9 +115,7 @@ describe('Cron', () => {
await app.init();
const registry = app.get(SchedulerRegistry);

expect(() => {
registry.getCronJob('DISABLED');
}).toThrow();
expect(registry.getCronJob('DISABLED').running).toBeFalsy();
});

it(`should return cron id by name`, async () => {
Expand Down

0 comments on commit 726cc8c

Please sign in to comment.