小编Raj*_*hal的帖子

CRON 作业在计划时间执行两次 (NestJS)

我想在我的 NestJs 项目中执行这个 cron 函数:

@Cron('59 23 * * *')
async CashPendingCRON(){
    let stores = await this.storeRepository.find();
    for (let store of stores){
        await this.connection
        .createQueryBuilder()
        .insert()
        .into(CashPending)
        .values([
        { cashPending: store.cashPending, store: store }
        ])
        .execute()
 }
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,玉米作业应该在每天晚上 11:59 执行。但它被执行了两次,并且条目被记录在数据库中两次。当我使用像 10 秒这样的间隔 (*/10 * * * * *) 时,它只会被调用一次。

如果有修复或者我做错了什么,请告诉我。

这是我在 app.module.ts 中添加 ScheduleModule 的方法

@Module({
  imports: [
    ScheduleModule.forRoot(),
    ConfigModule.forRoot({
      load: [appConfig, devConfig, stagConfig],
      ignoreEnvFile: true,
      isGlobal: true,
    }),
    TypeOrmModule.forRoot(
      configService.getTypeOrmConfig(),
    ),
    TypeOrmModule.forFeature([
      User,
      Vendor,
      Store,
      Product,
      Category,
      Brand,
      AppVersion …
Run Code Online (Sandbox Code Playgroud)

cron scheduled-tasks nestjs

3
推荐指数
1
解决办法
3136
查看次数

标签 统计

cron ×1

nestjs ×1

scheduled-tasks ×1