fix: 봇 스케줄러 botId 타입 불일치 수정
- registerBot, unregisterBot, isBotRunning에서 botId를 parseInt()로 정수 변환 - URL 파라미터(문자열)와 DB 조회 결과(숫자) 간 타입 일치 문제 해결 - 10초 상태 동기화에서 메모리 스케줄러를 찾지 못해 stopped로 변경되던 버그 수정
This commit is contained in:
parent
fc35a35987
commit
b161f1a9f7
1 changed files with 15 additions and 12 deletions
|
|
@ -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}] 스케줄 해제됨`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue