Can't get interval/cron working
allthesignals opened this issue · comments
Matt Gardner commented
app.schedule.ts:
import { Injectable } from '@nestjs/common';
import { Cron, Interval, Timeout, NestSchedule } from 'nest-schedule';
@Injectable() // Only support SINGLETON scope
export class ScheduleService extends NestSchedule {
@Cron('*/1 * * * *', {
startTime: new Date(),
})
async refreshMaterializedView() {
console.log('runs interval');
}
@Timeout(5)
onceJob() {
console.log('executing once job');
}
@Interval(5)
intervalJob() {
console.log('executing interval job');
// if you want to cancel the job, you should return true;
return true;
}
}
app.module.ts:
@Module({
imports: [
ProjectModule,
ContactModule,
TypeOrmModule.forRootAsync({
useFactory: (config: ConfigService) => ({
type: 'postgres',
url: config.get('DATABASE_URL'),
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: false,
}),
imports: [ConfigModule],
inject: [ConfigService],
}),
ConfigModule,
AuthModule,
DispositionModule,
OdataModule,
AssignmentModule,
DocumentModule,
ScheduleModule.register(), // here
],
controllers: [AppController],
})
Using Nest 6.0.0.
Not sure why but I'm not seeing any logging, or any indication that the class itself is instantiated. Anything I"m missing?
Edgar Pogosyan commented
I think you should specify ScheduleService
in providers list inside app.module.ts
. Or if ScheduleService
is in another module then import it inside AppModule