Reputation: 33
I want to execute the cron in nestjs locally and I have not found a way to test the cron locally.
example:
import { Cron } from '@nestjs/schedule';
@Injectable()
export class TasksService {
private readonly logger = new Logger(TasksService.name);
@Cron('45 * * * * *')
handleCron() {
this.logger.debug('Called when the current second is 45');
}
}
Upvotes: 1
Views: 1925
Reputation: 3461
Your service looks fine, you just need to activate it.
To activate job scheduling, import the ScheduleModule into the root AppModule and run the forRoot() static method as shown below:
import { Module } from '@nestjs/common';
import { ScheduleModule } from '@nestjs/schedule';
@Module({
imports: [
ScheduleModule.forRoot()
],
})
export class AppModule {}
Upvotes: 2