diff --git a/backend-node/src/controllers/smartFactoryLogController.ts b/backend-node/src/controllers/smartFactoryLogController.ts index 80158d41..6f98d37c 100644 --- a/backend-node/src/controllers/smartFactoryLogController.ts +++ b/backend-node/src/controllers/smartFactoryLogController.ts @@ -9,7 +9,6 @@ import { encryptionService } from "../services/encryptionService"; import { sendSmartFactoryLog, getTodayPlanStatus, - planDailySends, } from "../utils/smartFactoryLog"; /** @@ -278,10 +277,8 @@ export const upsertSchedule = async ( ] ); - // 스케줄 변경 시 오늘 계획 재생성 - await planDailySends(); - - res.json({ success: true, message: "스케줄이 저장되었습니다." }); + // 계획은 매일 00:05에만 생성 (즉시 재생성하면 지난 시각 소급 전송 위험) + res.json({ success: true, message: "스케줄이 저장되었습니다. 내일 00:05부터 적용됩니다." }); } catch (error) { logger.error("스케줄 저장 실패:", error); res.status(500).json({ success: false, message: "스케줄 저장 실패" }); diff --git a/backend-node/src/utils/smartFactoryLog.ts b/backend-node/src/utils/smartFactoryLog.ts index 2b1116b5..e491399f 100644 --- a/backend-node/src/utils/smartFactoryLog.ts +++ b/backend-node/src/utils/smartFactoryLog.ts @@ -145,9 +145,8 @@ export async function initSmartFactoryScheduler(): Promise { } }, { timezone: "Asia/Seoul" }); - // 서버 시작 시 오늘 계획이 아직 없으면 바로 생성 - await planDailySends(); - + // 서버 시작 시에는 계획 생성하지 않음 (00:05 cron에서만 생성) + // 서버 재시작 시 이미 지난 시각의 로그가 한꺼번에 전송되는 것 방지 logger.info("스마트공장 로그 스케줄러 초기화 완료 (매일 00:05 계획 생성, 매분 전송 실행)"); } @@ -250,10 +249,7 @@ async function executeScheduledSends(): Promise { if (entry.sent) continue; const entryMinute = entry.scheduledTime.getHours() * 60 + entry.scheduledTime.getMinutes(); - if (entryMinute > currentMinute) continue; // 아직 안 됨 - if (entryMinute < currentMinute) { - // 이미 지난 분인데 못 보낸 것 — 보냄 - } + if (entryMinute !== currentMinute) continue; // 정확히 해당 분에만 전송 // 전송 entry.sent = true;