From b161f1a9f753510f6840c3e9095034b312fbeff2 Mon Sep 17 00:00:00 2001 From: caadiq Date: Fri, 9 Jan 2026 19:31:11 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=B4=87=20=EC=8A=A4=EC=BC=80=EC=A4=84?= =?UTF-8?q?=EB=9F=AC=20botId=20=ED=83=80=EC=9E=85=20=EB=B6=88=EC=9D=BC?= =?UTF-8?q?=EC=B9=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - registerBot, unregisterBot, isBotRunning에서 botId를 parseInt()로 정수 변환 - URL 파라미터(문자열)와 DB 조회 결과(숫자) 간 타입 일치 문제 해결 - 10초 상태 동기화에서 메모리 스케줄러를 찾지 못해 stopped로 변경되던 버그 수정 --- backend/services/youtube-scheduler.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/backend/services/youtube-scheduler.js b/backend/services/youtube-scheduler.js index 353b829..37a6927 100644 --- a/backend/services/youtube-scheduler.js +++ b/backend/services/youtube-scheduler.js @@ -9,41 +9,44 @@ const schedulers = new Map(); * 봇이 메모리에서 실행 중인지 확인 */ export function isBotRunning(botId) { - return schedulers.has(botId); + const id = parseInt(botId); + return schedulers.has(id); } /** * 개별 봇 스케줄 등록 */ export function registerBot(botId, intervalMinutes = 2, cronExpression = null) { + const id = parseInt(botId); // 기존 스케줄이 있으면 제거 - unregisterBot(botId); + unregisterBot(id); // cron 표현식: 지정된 표현식 사용, 없으면 기본값 생성 const expression = cronExpression || `1-59/${intervalMinutes} * * * *`; const task = cron.schedule(expression, async () => { - console.log(`[Bot ${botId}] 동기화 시작...`); + console.log(`[Bot ${id}] 동기화 시작...`); try { - const result = await syncNewVideos(botId); - console.log(`[Bot ${botId}] 동기화 완료: ${result.addedCount}개 추가`); + const result = await syncNewVideos(id); + console.log(`[Bot ${id}] 동기화 완료: ${result.addedCount}개 추가`); } catch (error) { - console.error(`[Bot ${botId}] 동기화 오류:`, error.message); + console.error(`[Bot ${id}] 동기화 오류:`, error.message); } }); - schedulers.set(botId, task); - console.log(`[Bot ${botId}] 스케줄 등록됨 (cron: ${expression})`); + schedulers.set(id, task); + console.log(`[Bot ${id}] 스케줄 등록됨 (cron: ${expression})`); } /** * 개별 봇 스케줄 해제 */ export function unregisterBot(botId) { - if (schedulers.has(botId)) { - schedulers.get(botId).stop(); - schedulers.delete(botId); - console.log(`[Bot ${botId}] 스케줄 해제됨`); + const id = parseInt(botId); + if (schedulers.has(id)) { + schedulers.get(id).stop(); + schedulers.delete(id); + console.log(`[Bot ${id}] 스케줄 해제됨`); } }