我正在创建一个工人,将执行数据库操作及时。当我定义我的private readonly validationRuleRepository: ValidationRulesRepository,
时,它似乎没有注册cron。
ValidationRulesRepository的作用域也是Scope.DEFAULT
。
@Injectable({ scope: Scope.DEFAULT })
export class RulesCleanupWorker {
private readonly logger: Logger = new Logger(RulesCleanupWorker.name);
public constructor(
private readonly validationRuleRepository: ValidationRulesRepository,
) { }
@Cron(CronExpression.EVERY_30_SECONDS)
public async handleCron(): Promise<void> {
this.logger.debug('Starting to delete version 00 validation rules');
// await this.validationRuleRepository.deleteVersion00Rules();
this.logger.debug('ended clean up activity');
}
}
cronjob不执行,也未注册。我在日志中看到以下警告:
[Nest] 21620 - 05/29/2023, 2:01:22 PM LOG [RouterExplorer] Mapped {/api/vr-package/:id/copy-rules, POST} (version: 1) route +1ms
[Nest] 21620 - 05/29/2023, 2:01:22 PM WARN [Scheduler] Cannot register cron job "RulesCleanupWorker@handleCron" because it is defined in a non static provider.
[Nest] 21620 - 05/29/2023, 2:01:22 PM LOG [NestApplication] Nest application successfully started +0ms
1条答案
按热度按时间8ehkhllq1#
很可能您的
ValidationRulesRepository
注入了一个REQUEST
作用域的提供程序。如果不是仓库,那么可能是TypeORM模块的配置。如果最终将REQUEST
范围内的提供程序注入到scope: Scope.DEFAULT
或其依赖项之一,则无论是否指定scope: Scope.DEFAULT
,都不会改变该范围