All files / src/modules/boost boost.module.ts

84.61% Statements 11/13
75% Branches 3/4
0% Functions 0/2
81.81% Lines 9/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3711x 11x 11x 11x 11x 11x 11x 11x                     11x                                    
import { Module, OnModuleInit } from '@nestjs/common';
import { BullModule, InjectQueue } from '@nestjs/bullmq';
import { BoostService } from '@app/modules/boost/boost.service';
import { PaymentsService } from '@app/modules/boost/payments.service';
import { BoostController } from '@app/modules/boost/boost.controller';
import { BoostExpiryProcessor } from '@app/modules/boost/boost-expiry.processor';
import { PrismaModule } from '@app/modules/prisma/prisma.module';
import { Queue } from 'bullmq';
 
@Module({
  imports: [
    PrismaModule,
    BullModule.registerQueue({ name: 'boost-expiry' }),
    BullModule.registerQueue({ name: 'listingIndex' }),
  ],
  controllers: [BoostController],
  providers: [BoostService, PaymentsService, BoostExpiryProcessor],
})
export class BoostModule implements OnModuleInit {
  constructor(@InjectQueue('boost-expiry') private readonly boostExpiryQueue: Queue) {}
 
  async onModuleInit() {
    // Register a daily repeatable job with jitter ±10 minutes
    await this.boostExpiryQueue.add(
      'daily-check',
      {},
      {
        repeat: {
          cron: '0 3 * * *', // 03:00 UTC daily
          tz: 'UTC',
          jitter: 600, // seconds (10 minutes)
        } as any,
        jobId: 'boost-expiry-daily',
      },
    );
  }
}