Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get interval/cron working #43

Open
allthesignals opened this issue Dec 9, 2019 · 1 comment
Open

Can't get interval/cron working #43

allthesignals opened this issue Dec 9, 2019 · 1 comment

Comments

@allthesignals
Copy link

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-P-yan
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants