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}] 스케줄 해제됨`); } }