Chỉnh sửa và tối ưu form đăng nhập và đăng ký
This commit is contained in:
@@ -641,7 +641,7 @@ router.put('/scenes/:id', protect, uploadSinglePanorama, async (req, res) => {
|
||||
const processedFilePath = path.join(uploadDir, processedFileName);
|
||||
|
||||
await resizeTo8K(req.file.path, processedFilePath);
|
||||
await injectGPSCoordinates(processedFilePath, scene.lat, scene.lng);
|
||||
await injectGPSCoordinates(processedFilePath, scene.gps.lat, scene.gps.lng);
|
||||
|
||||
const asset = new Asset({
|
||||
filePath: processedFilePath,
|
||||
|
||||
@@ -16,12 +16,12 @@ const imageQueue = new Queue('image-processing', {
|
||||
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
|
||||
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: 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
|
||||
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
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const { Worker } = require('bullmq');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { connection } = require('./imageQueue');
|
||||
const { imageQueue, connection } = require('./imageQueue');
|
||||
const { resizeTo8K } = require('../utils/imageHelper');
|
||||
const { injectGPSCoordinates } = require('../utils/exifHelper');
|
||||
const Asset = require('../models/Asset');
|
||||
@@ -51,4 +51,20 @@ imageWorker.on('failed', (job, err) => {
|
||||
console.error(`Job ${job.id} thất bại sau nhiều lần thử: ${err.message}`);
|
||||
});
|
||||
|
||||
// Khi khởi động Worker, thực hiện dọn dẹp các job "stalled" hoặc dữ liệu rác
|
||||
// để đảm bảo Redis luôn sạch sẽ khi hệ thống khởi động lại.
|
||||
imageWorker.on('ready', async () => {
|
||||
console.log('[Worker] Sẵn sàng xử lý hàng đợi.');
|
||||
try {
|
||||
// Xóa các job hoàn thành quá 1 giờ và job thất bại quá 24 giờ
|
||||
// (Bổ trợ thêm cho cơ chế tự động dọn dẹp của Queue)
|
||||
await imageQueue.clean(3600000, 1000, 'completed');
|
||||
await imageQueue.clean(86400000, 1000, 'failed');
|
||||
|
||||
console.log('[Worker] Đã dọn dẹp các job cũ không cần thiết trong Redis.');
|
||||
} catch (err) {
|
||||
console.error('[Worker Cleanup Error]:', err.message);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = imageWorker;
|
||||
Reference in New Issue
Block a user