Chỉnh sửa phần upload ảnh

This commit is contained in:
2026-06-09 11:06:25 +07:00
parent 913867720f
commit 2fba77d50c
10 changed files with 171 additions and 27 deletions
+29
View File
@@ -0,0 +1,29 @@
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 };