Make queue UI optional and fix idle summary
This commit is contained in:
parent
76b3936ecd
commit
7206b454db
7 changed files with 165 additions and 64 deletions
|
|
@ -148,6 +148,7 @@ def _env_int(name: str, default: int) -> int:
|
|||
@dataclass(slots=True)
|
||||
class HostedDemoConfig:
|
||||
hosted_demo: bool
|
||||
show_queue_panel: bool
|
||||
max_upload_bytes: int
|
||||
max_input_dimension: int
|
||||
max_output_dimension: int
|
||||
|
|
@ -180,6 +181,7 @@ class HostedDemoConfig:
|
|||
spool_dir = Path(tempfile.gettempdir()) / "repixelizer-gui-spool"
|
||||
return cls(
|
||||
hosted_demo=hosted_demo,
|
||||
show_queue_panel=_env_flag("REPIXELIZER_SHOW_QUEUE_PANEL", hosted_demo),
|
||||
max_upload_bytes=max(1, _env_int("REPIXELIZER_MAX_UPLOAD_BYTES", defaults["max_upload_bytes"])),
|
||||
max_input_dimension=max(1, _env_int("REPIXELIZER_MAX_INPUT_DIMENSION", defaults["max_input_dimension"])),
|
||||
max_output_dimension=max(1, _env_int("REPIXELIZER_MAX_OUTPUT_DIMENSION", defaults["max_output_dimension"])),
|
||||
|
|
@ -200,6 +202,7 @@ class HostedDemoConfig:
|
|||
return {
|
||||
"showDeviceControl": not self.hosted_demo,
|
||||
"showStripBackgroundControl": not self.hosted_demo,
|
||||
"showQueuePanel": self.show_queue_panel,
|
||||
}
|
||||
|
||||
def public_payload(self) -> dict[str, Any]:
|
||||
|
|
@ -962,6 +965,7 @@ def create_app():
|
|||
"stateUrl": f"/api/jobs/{job.job_id}",
|
||||
"queuePosition": state_payload["queuePosition"],
|
||||
"queueDepth": state_payload["queueDepth"],
|
||||
"waitingCount": state_payload["waitingCount"],
|
||||
"queueCapacity": state_payload["queueCapacity"],
|
||||
"heartbeatIntervalSeconds": state_payload["heartbeatIntervalSeconds"],
|
||||
"staleAfterSeconds": state_payload["staleAfterSeconds"],
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ const phaseYInput = byId("phaseYInput");
|
|||
const stepsInput = byId("stepsInput");
|
||||
const seedInput = byId("seedInput");
|
||||
const runControlsCopy = byId("runControlsCopy");
|
||||
const queuePanel = byId("queuePanel");
|
||||
const queueSummaryPanel = byId("queueSummary");
|
||||
const cancelJobButton = byId("cancelJobButton");
|
||||
const deviceField = byId("deviceField");
|
||||
|
|
@ -182,6 +183,11 @@ function renderEventLog() {
|
|||
}
|
||||
}
|
||||
function renderQueueSummary() {
|
||||
if (!state.runtimeConfig?.ui.showQueuePanel) {
|
||||
queueSummaryPanel.innerHTML = "";
|
||||
cancelJobButton.hidden = true;
|
||||
return;
|
||||
}
|
||||
queueSummaryPanel.innerHTML = "";
|
||||
if (hasActiveJob()) {
|
||||
const cards = [
|
||||
|
|
@ -251,6 +257,15 @@ function setStage(stageKey, label, detail) {
|
|||
function hasActiveJob() {
|
||||
return state.jobId !== null && ["queued", "running", "waiting"].includes(state.status);
|
||||
}
|
||||
function queueSummaryFromState(activeStatus = state.status) {
|
||||
return {
|
||||
queueDepth: state.queueDepth,
|
||||
waitingCount: state.waitingCount,
|
||||
queueCapacity: state.queueCapacity || (state.runtimeConfig?.limits.queueCapacity ?? 0),
|
||||
hasActiveJob: state.queueDepth > 0,
|
||||
activeStatus,
|
||||
};
|
||||
}
|
||||
function formatByteLimit(bytes) {
|
||||
if (bytes >= 1024 * 1024) {
|
||||
return `${formatNumber(bytes / (1024 * 1024), 1)} MiB`;
|
||||
|
|
@ -287,6 +302,7 @@ function applyRuntimeConfig(config) {
|
|||
state.runtimeConfig = config;
|
||||
deviceField.hidden = !config.ui.showDeviceControl;
|
||||
stripBackgroundField.hidden = !config.ui.showStripBackgroundControl;
|
||||
queuePanel.hidden = !config.ui.showQueuePanel;
|
||||
stepsInput.max = String(config.limits.maxSteps);
|
||||
if (stepsInput.value.trim() === "" || Number(stepsInput.value) > config.limits.maxSteps || Number(stepsInput.value) === 48) {
|
||||
stepsInput.value = String(config.limits.defaultSteps);
|
||||
|
|
@ -526,14 +542,19 @@ function renderStatusMetrics() {
|
|||
const items = [];
|
||||
const frame = getSelectedFrame();
|
||||
if (state.stageKey === "queued" || state.status === "queued" || state.status === "waiting") {
|
||||
items.push({
|
||||
label: "Line",
|
||||
value: state.queuePosition === null || state.queueDepth <= 0
|
||||
? "pending"
|
||||
: `${state.queuePosition} / ${Math.max(state.queueDepth, state.queuePosition)}`,
|
||||
});
|
||||
items.push({ label: "Waiting", value: `${state.waitingCount} / ${state.queueCapacity || (state.runtimeConfig?.limits.queueCapacity ?? 0)}` });
|
||||
items.push({ label: "Heartbeat", value: `${state.heartbeatIntervalSeconds}s` });
|
||||
if (state.runtimeConfig?.ui.showQueuePanel) {
|
||||
items.push({
|
||||
label: "Line",
|
||||
value: state.queuePosition === null || state.queueDepth <= 0
|
||||
? "pending"
|
||||
: `${state.queuePosition} / ${Math.max(state.queueDepth, state.queuePosition)}`,
|
||||
});
|
||||
items.push({
|
||||
label: "Waiting",
|
||||
value: `${state.waitingCount} / ${state.queueCapacity || (state.runtimeConfig?.limits.queueCapacity ?? 0)}`,
|
||||
});
|
||||
items.push({ label: "Heartbeat", value: `${state.heartbeatIntervalSeconds}s` });
|
||||
}
|
||||
}
|
||||
else if (state.stageKey === "inference") {
|
||||
if (state.latticeSearch) {
|
||||
|
|
@ -1120,6 +1141,11 @@ async function loadRuntimeConfig() {
|
|||
applyRuntimeConfig((await response.json()));
|
||||
}
|
||||
async function refreshQueueSummary() {
|
||||
if (!state.runtimeConfig?.ui.showQueuePanel) {
|
||||
state.queueSummary = null;
|
||||
renderQueueSummary();
|
||||
return;
|
||||
}
|
||||
if (hasActiveJob()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1137,6 +1163,10 @@ function stopQueuePolling() {
|
|||
}
|
||||
}
|
||||
function syncQueuePolling() {
|
||||
if (!state.runtimeConfig?.ui.showQueuePanel) {
|
||||
stopQueuePolling();
|
||||
return;
|
||||
}
|
||||
if (hasActiveJob()) {
|
||||
stopQueuePolling();
|
||||
return;
|
||||
|
|
@ -1280,13 +1310,7 @@ async function handleEvent(eventName, payload) {
|
|||
break;
|
||||
case "queue_state":
|
||||
applyQueueState(payload);
|
||||
state.queueSummary = {
|
||||
queueDepth: state.queueDepth,
|
||||
waitingCount: state.waitingCount,
|
||||
queueCapacity: state.queueCapacity,
|
||||
hasActiveJob: state.queueDepth > 0,
|
||||
activeStatus: state.status,
|
||||
};
|
||||
state.queueSummary = queueSummaryFromState();
|
||||
break;
|
||||
case "job_canceled":
|
||||
stopHeartbeat();
|
||||
|
|
@ -1295,8 +1319,8 @@ async function handleEvent(eventName, payload) {
|
|||
addLog("Canceled", String(payload.message ?? "Canceled the job."));
|
||||
runButton.disabled = false;
|
||||
currentEventSource?.close();
|
||||
await refreshQueueSummary().catch(() => undefined);
|
||||
syncQueuePolling();
|
||||
void refreshQueueSummary().catch(() => undefined);
|
||||
break;
|
||||
case "job_failed":
|
||||
stopHeartbeat();
|
||||
|
|
@ -1305,8 +1329,8 @@ async function handleEvent(eventName, payload) {
|
|||
addLog("Failure", String(payload.message ?? "The run failed."));
|
||||
runButton.disabled = false;
|
||||
currentEventSource?.close();
|
||||
await refreshQueueSummary().catch(() => undefined);
|
||||
syncQueuePolling();
|
||||
void refreshQueueSummary().catch(() => undefined);
|
||||
break;
|
||||
case "stage_started":
|
||||
setJobState("running");
|
||||
|
|
@ -1482,8 +1506,8 @@ async function handleEvent(eventName, payload) {
|
|||
runButton.disabled = false;
|
||||
currentEventSource?.close();
|
||||
await loadEditorAsset(state.finalOutputImage);
|
||||
await refreshQueueSummary().catch(() => undefined);
|
||||
syncQueuePolling();
|
||||
void refreshQueueSummary().catch(() => undefined);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -1537,13 +1561,7 @@ async function startRun() {
|
|||
const payload = (await response.json());
|
||||
state.jobId = payload.jobId;
|
||||
applyJobSnapshot(payload);
|
||||
state.queueSummary = {
|
||||
queueDepth: payload.queueDepth,
|
||||
waitingCount: payload.waitingCount,
|
||||
queueCapacity: payload.queueCapacity,
|
||||
hasActiveJob: payload.queueDepth > 0,
|
||||
activeStatus: payload.status,
|
||||
};
|
||||
state.queueSummary = queueSummaryFromState(payload.status);
|
||||
connectEventStream(payload.jobId);
|
||||
syncHeartbeat();
|
||||
syncQueuePolling();
|
||||
|
|
@ -1784,11 +1802,13 @@ async function initializeApp() {
|
|||
catch (error) {
|
||||
addLog("Config", error instanceof Error ? error.message : "Failed to load runtime config.");
|
||||
}
|
||||
try {
|
||||
await refreshQueueSummary();
|
||||
}
|
||||
catch (error) {
|
||||
addLog("Queue", error instanceof Error ? error.message : "Failed to load queue summary.");
|
||||
if (state.runtimeConfig?.ui.showQueuePanel) {
|
||||
try {
|
||||
await refreshQueueSummary();
|
||||
}
|
||||
catch (error) {
|
||||
addLog("Queue", error instanceof Error ? error.message : "Failed to load queue summary.");
|
||||
}
|
||||
}
|
||||
syncQueuePolling();
|
||||
await renderEverything();
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@
|
|||
<button id="runButton" class="button" type="button">Run The Machine</button>
|
||||
</section>
|
||||
|
||||
<section class="card sidebar-section ui-surface ui-frame">
|
||||
<section id="queuePanel" class="card sidebar-section ui-surface ui-frame" hidden>
|
||||
<div class="card-head">
|
||||
<div class="copy-stack">
|
||||
<h2>Queue</h2>
|
||||
|
|
|
|||
Loading…
Reference in a new issue