Use execution boundary for active job start time
This commit is contained in:
@@ -29,7 +29,7 @@ function statusFromHistory(entry) { const status = entry?.status || {}; const fa
|
||||
function promptPayload(entry) { const prompt = entry?.prompt; return Array.isArray(prompt) ? (prompt[2] || {}) : (prompt || {}); }
|
||||
function extraData(entry) { const prompt = entry?.prompt; return Array.isArray(prompt) ? (prompt[3] || {}) : (prompt?.extra_data || {}); }
|
||||
function statusTimestamp(entry, messageName) { const message = (entry?.status?.messages || []).find((item) => item?.[0] === messageName); const payload = message?.[1]; return typeof payload === 'number' ? payload : typeof payload?.timestamp === 'number' ? payload.timestamp : null; }
|
||||
function durationMs(entry) { const start = statusTimestamp(entry, 'execution_start'); const end = statusTimestamp(entry, 'execution_success') || statusTimestamp(entry, 'execution_error'); return start && end && end >= start ? end - start : null; }
|
||||
function durationMs(entry, promptId = '') { const start = statusTimestamp(entry, 'execution_start') || executionStarts.get(String(promptId || '').trim()); const end = statusTimestamp(entry, 'execution_success') || statusTimestamp(entry, 'execution_error'); return start && end && end >= start ? end - start : null; }
|
||||
function modelName(value) { if (typeof value !== 'string' || !value.trim()) return null; return value.trim(); }
|
||||
function modelsFromPrompt(entry) {
|
||||
const modelKeys = new Set(['ckpt_name', 'checkpoint_name', 'unet_name', 'diffusion_model', 'model_name', 'lora_name', 'control_net_name', 'vae_name', 'clip_name', 'clip_name1', 'clip_name2', 'style_model_name', 'upscale_model']);
|
||||
@@ -78,12 +78,15 @@ function startComfyProgressSocket() {
|
||||
if (message.type === 'progress') liveProgress.set(data.prompt_id, { value: Number(data.value) || 0, max: Number(data.max) || 1 });
|
||||
if (message.type === 'execution_start') {
|
||||
const timestamp = Number(data.timestamp);
|
||||
if (Number.isFinite(timestamp) && timestamp > 0) executionStarts.set(data.prompt_id, timestamp);
|
||||
// Some ComfyUI builds omit timestamp from the websocket event even
|
||||
// though the event itself is emitted at the real execution boundary.
|
||||
// Receipt time is therefore the narrowest safe fallback; it is never
|
||||
// based on when the portal page was opened or refreshed.
|
||||
executionStarts.set(data.prompt_id, Number.isFinite(timestamp) && timestamp > 0 ? timestamp : Date.now());
|
||||
liveProgress.set(data.prompt_id, { value: 0, max: 1 });
|
||||
}
|
||||
if (message.type === 'executing' && data.node === null) {
|
||||
liveProgress.delete(data.prompt_id);
|
||||
executionStarts.delete(data.prompt_id);
|
||||
}
|
||||
} catch { /* Ignore malformed progress events. */ }
|
||||
});
|
||||
@@ -97,7 +100,7 @@ function jobFromHistory(promptId, entry) {
|
||||
const metadata = extraData(entry);
|
||||
const progress = liveProgress.get(promptId);
|
||||
const startedAt = statusTimestamp(entry, 'execution_start') || executionStarts.get(promptId) || null;
|
||||
return { promptId, title: metadata.title || 'Untitled job', status: statusFromHistory(entry), queuedAt: startedAt, completedAt: statusTimestamp(entry, 'execution_success') || statusTimestamp(entry, 'execution_error'), durationMs: durationMs(entry), outputCount: assets.length, assets, models: modelsFromPrompt(entry), progress: progress ? { value: progress.value, max: progress.max, percent: Math.min(100, Math.round((progress.value / progress.max) * 100)) } : null };
|
||||
return { promptId, title: metadata.title || 'Untitled job', status: statusFromHistory(entry), queuedAt: startedAt, completedAt: statusTimestamp(entry, 'execution_success') || statusTimestamp(entry, 'execution_error'), durationMs: durationMs(entry, promptId), outputCount: assets.length, assets, models: modelsFromPrompt(entry), progress: progress ? { value: progress.value, max: progress.max, percent: Math.min(100, Math.round((progress.value / progress.max) * 100)) } : null };
|
||||
}
|
||||
function jobFromQueue(item, historyEntry) { const [queueNumber, promptId, prompt, extraData] = item || []; const id = String(promptId || `queued-${queueNumber}`); return jobFromHistory(id, historyEntry || { prompt: [queueNumber, promptId, prompt || {}, extraData || {}], status: {}, outputs: {} }); }
|
||||
async function listJobs() { const [history, queue] = await Promise.all([comfyJson('/history'), comfyJson('/queue')]); const jobs = Object.entries(history || {}).map(([promptId, entry]) => jobFromHistory(promptId, entry)).sort((a, b) => (b.completedAt || b.queuedAt || 0) - (a.completedAt || a.queuedAt || 0)); const runningItems = Array.isArray(queue?.queue_running) ? queue.queue_running : []; const running = runningItems.map((item) => jobFromQueue(item, history?.[String(item?.[1] || '')])).at(0) || null; return { jobs, running }; }
|
||||
|
||||
Reference in New Issue
Block a user