miaowing / nest-schedule

A cron-like and not-cron-like job distributed scheduler for Nest.js by decorators.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynamic cron job not wokring

sandeepsuvit opened this issue · comments

Hi, i was trying to create a scheduler using dynamic cron job like so when my module initialises

@Injectable()
export class NotificationsService implements OnModuleInit {
    constructor(
        @InjectSchedule() private readonly schedule: Schedule,
    ) { }

    onModuleInit() {
        // Trigger every 10 seconds
        this.schedule.scheduleCronJob('cron', '*/10 * * * * *', () => {
            console.log('executing my custom interval job');
            return false;
        });
    }
}

When i start the server i get this error in the console

(node:45897) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startTime' of undefined

which is weird because as per the method params the startTime and endTime are optional

scheduleCronJob(key: string, cron: string, callback: JobCallback, config?: ICronJobConfig): void;
...
export interface ICronJobConfig extends IJobConfig {
    startTime?: Date;
    endTime?: Date;
}

Am i missing something here?

Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.