targo-backend/src/modules/attachments/services/variants.queue.ts

22 lines
642 B
TypeScript

import { Injectable } from "@nestjs/common";
import { Queue } from "bullmq";
@Injectable()
export class VariantsQueue {
private queue: Queue;
constructor() {
const name = `${process.env.BULL_PREFIX || 'attachments'}:variants`;
this.queue = new Queue(name, { connection: { url: process.env.REDIS_URL! } });
}
enqueue(attachment_id: number, mime: string) {
if (!mime.startsWith('image/')) return Promise.resolve();
return this.queue.add(
'generate',
{ attachment_id, mime },
{ attempts: 3, backoff: { type: 'exponential', delay: 2000 } }
);
}
}