fix: restore watcher elapsed status updates

This commit is contained in:
Eyejoker
2026-03-23 05:22:52 +09:00
parent 7c6019dea3
commit 127eacb564
2 changed files with 54 additions and 0 deletions

View File

@@ -140,10 +140,28 @@ function formatWatchIntervalLabel(
return minutes > 0 ? `${hours}시간 ${minutes}` : `${hours}시간`;
}
function formatElapsedLabel(startedAtIso: string, checkedAtIso: string): string {
const elapsedMs = Math.max(
0,
new Date(checkedAtIso).getTime() - new Date(startedAtIso).getTime(),
);
const totalSeconds = Math.floor(elapsedMs / 1000);
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
const parts: string[] = [];
if (hours > 0) parts.push(`${hours}시간`);
if (minutes > 0) parts.push(`${minutes}`);
parts.push(`${seconds}`);
return parts.join(' ');
}
export function renderWatchCiStatusMessage(args: {
task: Pick<ScheduledTask, 'prompt' | 'schedule_type' | 'schedule_value'>;
phase: WatcherStatusPhase;
checkedAt: string;
statusStartedAt?: string | null;
nextRun?: string | null;
}): string {
const target = extractWatchCiTarget(args.task.prompt) || 'CI watcher';
@@ -165,6 +183,11 @@ export function renderWatchCiStatusMessage(args: {
`- 상태: ${statusLabel}`,
`- 마지막 확인: ${formatTimeLabel(args.checkedAt)}`,
];
if (args.statusStartedAt) {
lines.push(
`- 경과 시간: ${formatElapsedLabel(args.statusStartedAt, args.checkedAt)}`,
);
}
const intervalLabel = formatWatchIntervalLabel(args.task);
if (intervalLabel) {
lines.push(`- 확인 간격: ${intervalLabel}`);
@@ -290,6 +313,7 @@ async function runTask(
task,
phase,
checkedAt,
statusStartedAt,
nextRun,
});
const payload = `${TASK_STATUS_MESSAGE_PREFIX}${text}`;