import { InjectQueue } from '@nestjs/bullmq';
import { Injectable } from '@nestjs/common';
import { Queue } from 'bullmq';
import { S3_CLEANUP_QUEUE } from './queue.constants';

@Injectable()
export class S3CleanupQueue {
  constructor(@InjectQueue(S3_CLEANUP_QUEUE) private readonly queue: Queue) {}

  async enqueueDelete(key: string) {
    await this.queue.add(
      'delete-object',
      { key },
      { attempts: 5, backoff: { type: 'exponential', delay: 5000 }, removeOnComplete: true, removeOnFail: false },
    );
  }
}
