refactor: Update smart factory log scheduling behavior
- Removed immediate plan generation on server start to prevent sending logs for past timestamps. - Updated the upsertSchedule response message to clarify that the schedule will take effect from the next day at 00:05. These changes aim to enhance the reliability of the smart factory log scheduling system by ensuring that logs are sent at the correct times and reducing the risk of sending outdated logs.
This commit is contained in:
@@ -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: "스케줄 저장 실패" });
|
||||
|
||||
@@ -145,9 +145,8 @@ export async function initSmartFactoryScheduler(): Promise<void> {
|
||||
}
|
||||
}, { timezone: "Asia/Seoul" });
|
||||
|
||||
// 서버 시작 시 오늘 계획이 아직 없으면 바로 생성
|
||||
await planDailySends();
|
||||
|
||||
// 서버 시작 시에는 계획 생성하지 않음 (00:05 cron에서만 생성)
|
||||
// 서버 재시작 시 이미 지난 시각의 로그가 한꺼번에 전송되는 것 방지
|
||||
logger.info("스마트공장 로그 스케줄러 초기화 완료 (매일 00:05 계획 생성, 매분 전송 실행)");
|
||||
}
|
||||
|
||||
@@ -250,10 +249,7 @@ async function executeScheduledSends(): Promise<void> {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user