const { Queue } = require('bullmq'); const IORedis = require('ioredis'); // Cấu hình kết nối Redis (Mặc định localhost:6379) const connection = new IORedis({ maxRetriesPerRequest: null }); /** * Khởi tạo hàng đợi xử lý ảnh */ const imageQueue = new Queue('image-processing', { connection, defaultJobOptions: { attempts: 3, // Thử lại tối đa 3 lần nếu lỗi backoff: { type: 'exponential', delay: 5000 }, // Tự động dọn dẹp Job để tối ưu bộ nhớ Redis removeOnComplete: { age: 3600, // Xóa các job hoàn thành sau 1 giờ (3600 giây) count: 100 // Hoặc giữ tối đa 100 job hoàn thành gần nhất }, removeOnFail: { age: 24 * 3600, // Giữ lại job lỗi trong 24 giờ để admin kiểm tra count: 500 // Giữ tối đa 500 job lỗi } } }); module.exports = { imageQueue, connection };