2024-09-02 04:36:41 +00:00
|
|
|
import { injectable } from "tsyringe";
|
2024-08-07 15:13:36 +00:00
|
|
|
import { Queue, Worker, type Processor } from 'bullmq';
|
2024-09-02 04:36:41 +00:00
|
|
|
import RedisClient from "ioredis";
|
|
|
|
|
import { config } from "../common/config";
|
|
|
|
|
|
|
|
|
|
// BullMQ utilizes ioredis, which is no longer maintained but still works fine.
|
|
|
|
|
// I recommend using BullMQ with ioredis for now, but keep an eye out for future updates.
|
2024-08-07 15:13:36 +00:00
|
|
|
|
|
|
|
|
@injectable()
|
|
|
|
|
export class JobsService {
|
2024-09-02 04:36:41 +00:00
|
|
|
constructor() { }
|
2024-08-07 15:13:36 +00:00
|
|
|
|
|
|
|
|
createQueue(name: string) {
|
2024-09-02 04:36:41 +00:00
|
|
|
return new Queue(name, {
|
|
|
|
|
connection: new RedisClient(config.redis.url, {
|
|
|
|
|
maxRetriesPerRequest: null
|
|
|
|
|
})
|
|
|
|
|
})
|
2024-08-07 15:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createWorker(name: string, prcoessor: Processor) {
|
2024-09-02 04:36:41 +00:00
|
|
|
return new Worker(name, prcoessor, {
|
|
|
|
|
connection: new RedisClient(config.redis.url, {
|
|
|
|
|
maxRetriesPerRequest: null
|
|
|
|
|
})
|
|
|
|
|
})
|
2024-08-07 15:13:36 +00:00
|
|
|
}
|
|
|
|
|
}
|