한글뷰어 기능수정 Ver.01

This commit is contained in:
koj729
2026-06-19 17:58:47 +09:00
parent 9268e4e6bc
commit 83b6e891ab
49 changed files with 8741 additions and 446 deletions

View File

@@ -2,7 +2,6 @@ const { Queue, QueueEvents, Job, Worker } = require('bullmq');
const { redisConnection } = require('./config/redis.js');
const { getIo } = require('./socket');
const axios = require('axios');
const controllers = require(`./controllers/archiveController.js`);
const { GoogleGenerativeAI } = require('@google/generative-ai');
const pool = require('./db/pool.js');
const { GetObjectCommand } = require('@aws-sdk/client-s3');
@@ -182,7 +181,7 @@ summarizeAIQueueEvents.on('completed', async({ jobId, returnvalue }) => {
type: type
};
await controllers.addSummarizeAiLog(addSummarizeAiLogParams);
await require('./controllers/archiveController.js').addSummarizeAiLog(addSummarizeAiLogParams);
}
});
@@ -266,7 +265,7 @@ summarizeAPIQueueEvents.on('completed', async({ jobId, returnvalue }) => {
isState: true
};
await controllers.addSummarizeAiLog(addSummarizeAiLogParams);
await require('./controllers/archiveController.js').addSummarizeAiLog(addSummarizeAiLogParams);
}
});
@@ -515,5 +514,73 @@ const summarizeAPIWorker = new Worker('api-summarize', async (job) => {
lockDuration: 90000 // lock 유지 시간을 90초로 늘려 stalled 에러 방지
});
module.exports = { convertPdfQueue, zipFolderQueue, thumbQueue, postProcessVideoQueue, summarizeAIQueue, summarizeAPIQueue };
// 🔻🔻🔻🔻🔻🔻🔻🔻 worker7 활동로그 비동기 적재 관련 내용 시작 🔻🔻🔻🔻🔻🔻🔻🔻
const activityLogQueue = new Queue('activity-log', { connection: redisConnection });
function makePostgresTimestamp(date) {
if (date) date = new Date(date);
else date = new Date(Date.now());
// Intl API로 현재 시스템 타임존 확인
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
// KST 변환이 필요한 경우에만 UTC + 9시간 적용
const isUtcOrNonSeoul = !timeZone || timeZone !== 'Asia/Seoul';
date = isUtcOrNonSeoul ? new Date(date.getTime() + 9 * 60 * 60 * 1000) : date;
let YYYY = date.getFullYear();
let MM = String(date.getMonth() + 1).padStart(2, '0');
let DD = String(date.getDate()).padStart(2, '0');
let HH = String(date.getHours()).padStart(2, '0');
let mm = String(date.getMinutes()).padStart(2, '0');
let ss = String(date.getSeconds()).padStart(2, '0');
let SSS = String(date.getMilliseconds()).padStart(3, '0');
return `${YYYY}-${MM}-${DD} ${HH}:${mm}:${ss}.${SSS}`;
}
async function addActivityLogJob(logData) {
await activityLogQueue.add('insert-log', logData, {
removeOnComplete: 100, // 완료된 작업 보관 개수 제한
attempts: 3, // DB 지연 시 최대 3회 재시도
backoff: 5000 // 재시도 간격 5초
});
}
const activityLogWorker = new Worker('activity-log', async (job) => {
const { projectId, activity, userId, userIp, targetPath, status, logDate, metaData } = job.data;
const client = await pool.connect();
try {
const env = process.env.NODE_ENV;
const tbLog = env === 'production' ? 'tb_log' : '_test_tb_log';
const formattedLogDate = makePostgresTimestamp(logDate);
await client.query(`
INSERT INTO ver4.${tbLog} (project_id, activity, user_id, user_ip, log_date, path_arr, status, meta_data)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
`, [projectId, activity, userId, userIp, formattedLogDate, [targetPath], status, JSON.stringify(metaData)]);
} catch (err) {
console.error("Failed to write activity log to DB:", err);
throw err; // triggers BullMQ retry logic
} finally {
client.release();
}
}, {
connection: redisConnection,
lockDuration: 30000
});
// 🔺🔺🔺🔺🔺🔺🔺🔺 worker7 활동로그 관련 내용 끝 🔺🔺🔺🔺🔺🔺🔺🔺
module.exports = {
convertPdfQueue,
zipFolderQueue,
thumbQueue,
postProcessVideoQueue,
summarizeAIQueue,
summarizeAPIQueue,
activityLogQueue,
addActivityLogJob
};