All files / src/modules/media media-gc.scheduler.ts

100% Statements 10/10
75% Branches 3/4
100% Functions 2/2
100% Lines 8/8

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 1912x 12x 12x 12x     12x 1x       12x 1x            
import { Injectable } from '@nestjs/common';
import { Cron, CronExpression } from '@nestjs/schedule';
import { InjectQueue } from '@nestjs/bullmq';
import { Queue } from 'bullmq';
 
@Injectable()
export class MediaGcScheduler {
  constructor(@InjectQueue('media-gc') private readonly gcQueue: Queue) {}
 
  // Run every day at 03:00 UTC
  @Cron(CronExpression.EVERY_DAY_AT_2AM)
  async enqueueGc() {
    await this.gcQueue.add('gc', {}, {
      jobId: `media-gc-${Date.now()}`,
      removeOnComplete: true,
      removeOnFail: true,
    });
  }
}