Chỉnh sửa và tối ưu form đăng nhập và đăng ký

This commit is contained in:
2026-06-09 12:22:29 +07:00
parent 2fba77d50c
commit 9f9c38e6e7
9 changed files with 357 additions and 32 deletions
+17 -1
View File
@@ -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;