// src/lib/server/processes.ts
import type { ChildProcess } from 'child_process';

export interface ProcessInfo {
    id: string;
    startTime: number;
    status: 'running' | 'completed' | 'error' | 'cancelled';
    progress: number;
    message?: string;
}

export const activeProcesses = new Map<string, ChildProcess>();
export const processInfo = new Map<string, ProcessInfo>();

// cleanup interval (10분 주기)
setInterval(() => {
    const now = Date.now();
    for (const [id, info] of processInfo.entries()) {
        if (info.status !== 'running' && now - info.startTime > 10 * 60 * 1000) {
            console.log(`🧹 Removing expired process info: ${id}`);
            processInfo.delete(id);
        }
    }
}, 10 * 60 * 1000);
