Files
3dtours/backend/routes/imageQueue.js
T
2026-06-12 07:59:10 +07:00

31 lines
1.1 KiB
JavaScript

const { Queue } = require('bullmq');
const IORedis = require('ioredis');
// Cấu hình kết nối Redis sử dụng biến môi trường từ Docker
const connection = new IORedis({
host: process.env.REDIS_HOST || '127.0.0.1',
port: process.env.REDIS_PORT || 6379,
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: 1800, // Xóa các job hoàn thành sau 30 phút (1800 giây) để giải phóng RAM nhanh hơn
count: 50 // Chỉ giữ 50 job gần nhất (đủ để xem log gần đây)
},
removeOnFail: {
age: 12 * 3600, // Giữ lại job lỗi trong 12 giờ để admin kiểm tra
count: 100 // Giữ tối đa 100 job lỗi
}
}
});
module.exports = { imageQueue, connection };