Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Let a waiting video move to the front of the queue

Bowen Xuecdb7ab67fbc6
diff --git a/freevideo_engine/chain_runner.py b/freevideo_engine/chain_runner.py
index f48c478..cf71f20 100644
--- a/freevideo_engine/chain_runner.py
+++ b/freevideo_engine/chain_runner.py
@@ -300,6 +300,12 @@ class ChainRunner:
return record, block
return None, None
+ def owns(self, prompt_id):
+ """True while a chain block submitted this host request; its order is the chain's."""
+ with self.lock:
+ return any(row['prompt_id'] == prompt_id and row['state'] in ('queued', 'running')
+ for record in self.records.values() for row in record['blocks'])
+
def _start(self, block):
if block['started'] is None:
block['started'] = self.wall()
diff --git a/freevideo_engine/comfy_progress.py b/freevideo_engine/comfy_progress.py
index 32126c3..12b49a0 100644
--- a/freevideo_engine/comfy_progress.py
+++ b/freevideo_engine/comfy_progress.py
@@ -1,6 +1,7 @@
"""Transient progress snapshots for reopened ComfyUI tabs; no request inputs."""
from copy import deepcopy
from pathlib import Path
+import heapq
import threading
import time
import uuid
@@ -242,6 +243,30 @@ def cancel_request(queue, prompt_id, node_id, interrupt):
return 'finished'
+def move_request_first(queue, prompt_id, node_id, protected=lambda prompt_id: False):
+ """Put exactly this waiting FreeVideo request ahead of every other waiting one.
+
+ Comfy runs the smallest queue number first, so the request takes a number
+ below the current smallest. Everything else keeps its relative order.
+ """
+ with queue.mutex:
+ waiting = queue.queue
+ row = next((row for row in waiting if row[1] == prompt_id
+ and row[2].get(str(node_id), {}).get('class_type') == 'FreeVideoGenerate'), None)
+ if row is None:
+ running = any(item[1] == prompt_id for item in queue.currently_running.values())
+ return 'running' if running else 'finished'
+ if protected(prompt_id):
+ return 'unavailable'
+ if row is min(waiting):
+ return 'first'
+ index = next(i for i, item in enumerate(waiting) if item is row)
+ waiting[index] = (min(item[0] for item in waiting) - 1,) + tuple(row[1:])
+ heapq.heapify(waiting)
+ queue.server.queue_updated()
+ return 'moved'
+
+
def register():
import asyncio
from aiohttp import web
@@ -279,3 +304,14 @@ def register():
import nodes
return web.json_response({'status': cancel_request(server.prompt_queue, prompt_id,
node_id, nodes.interrupt_processing)})
+
+ @server.routes.post('/freevideo/queue/first')
+ async def queue_first(request):
+ value = await request.json()
+ prompt_id, node_id = value.get('prompt_id'), value.get('node_id')
+ if not isinstance(prompt_id, str) or not prompt_id or not isinstance(node_id, str):
+ return web.json_response({'error': 'A request and node ID are required'}, status=400)
+ from . import comfy_chain
+ runner = comfy_chain.RUNNER
+ return web.json_response({'status': move_request_first(server.prompt_queue, prompt_id, node_id,
+ runner.owns if runner is not None else (lambda prompt_id: False))})
diff --git a/web/studio.css b/web/studio.css
index f599276..1a8b7b6 100644
--- a/web/studio.css
+++ b/web/studio.css
@@ -112,9 +112,11 @@
.fv-studio .fv-run-menu .fv-field{padding:10px 8px 0}.fv-studio .fv-run-menu p{margin:10px 8px 2px;line-height:1.6}
.fv-studio .fv-queue-actions{display:flex;align-items:center;justify-content:center;gap:4px;flex-wrap:wrap;margin-top:8px}
.fv-studio .fv-queue-actions button,.fv-studio .fv-queue-details>summary{padding:4px 8px;min-height:28px;font-size:var(--fv-micro);color:var(--fv-muted)}
-.fv-studio .fv-queue-details{position:relative}.fv-studio .fv-queue-details>summary{cursor:pointer;list-style:none}
+.fv-studio .fv-queue-actions{position:relative}.fv-studio .fv-queue-details{position:static}.fv-studio .fv-queue-details>summary{cursor:pointer;list-style:none}
.fv-studio .fv-queue-list{left:0;right:auto;bottom:calc(100% + var(--fv-h-lg) + 24px);width:300px;max-height:260px;overflow:auto;scrollbar-width:thin}
.fv-studio .fv-queue-item{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:var(--fv-micro);padding:3px 0;white-space:nowrap}
+.fv-studio .fv-queue-item span{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis}
+.fv-studio .fv-queue-item button{flex:none}
.fv-studio .fv-status{min-height:22px;text-align:center;font-size:var(--fv-micro);color:var(--fv-muted);overflow-wrap:anywhere}.fv-studio .fv-status[data-error=true]{color:var(--fv-danger)}
.fv-studio .fv-progress{width:100%;height:4px;accent-color:var(--fv-accent);border:0;margin:0 0 10px}.fv-studio .fv-budget,.fv-studio .fv-prewarm{text-align:center;font-size:var(--fv-micro);color:var(--fv-muted)}
.fv-studio .fv-panel{height:auto;padding:0;border:none;border-radius:0;background:transparent;color:var(--fv-ink);font-size:var(--fv-micro);overflow:visible}
diff --git a/web/studio.js b/web/studio.js
index 702026a..23f501e 100644
--- a/web/studio.js
+++ b/web/studio.js
@@ -1019,6 +1019,7 @@ export function openStudio(node, {extendFrom = null} = {}) {
const queueError = error => ({
queue_unavailable: t('Could not read the queue. Any loop has been stopped; already submitted videos stay queued.', '暂时无法读取队列。循环已停止追加,已提交的任务仍在队列中。'),
cancel_failed: t('Could not cancel. Try again.', '暂时未能取消,请重试。'),
+ move_failed: t('Could not move it. Try again.', '暂时未能移动,请重试。'),
submit_failed: t('The workflow was not queued. Check the node settings.', '工作流未能提交,请检查节点设置。'),
loop_active: t('Stop the current loop before starting another.', '请先停止当前循环。'),
loop_stopped: t('The last request did not complete. The loop has stopped.', '上一条任务未完成,循环已停止。'),
@@ -1113,7 +1114,17 @@ export function openStudio(node, {extendFrom = null} = {}) {
catch (error) { showQueueError(error); remove.disabled = false; }
}, 'fv-quiet');
remove.setAttribute('aria-label', t(`Remove queued video ${index + 1}`, `移除第 ${index + 1} 条排队任务`));
- item.append(description, remove); queueList.append(item);
+ item.append(description);
+ if (index > 0) {
+ const first = button(t('Move to front', '排到最前'), async () => {
+ first.disabled = remove.disabled = true;
+ try { await queueController.moveFirst(row.id); }
+ catch (error) { showQueueError(error); first.disabled = remove.disabled = false; }
+ }, 'fv-quiet');
+ first.setAttribute('aria-label', t(`Move queued video ${index + 1} to front`, `把第 ${index + 1} 条排队任务排到最前`));
+ item.append(first);
+ }
+ item.append(remove); queueList.append(item);
});
}
if (!busy) cancelling = false;
diff --git a/web/studio_queue.js b/web/studio_queue.js
index 25a7bd7..dd7796a 100644
--- a/web/studio_queue.js
+++ b/web/studio_queue.js
@@ -124,6 +124,16 @@ export function createStudioQueue(api, nodeId, {random = randomSeed, pollMs = 20
if (!response.ok) throw new Error('cancel_failed');
return response.json();
}
+ // The page changes its list only after the server says where the request now is.
+ async function moveFirst(id) {
+ const response = await api.fetchApi('/freevideo/queue/first', {method: 'POST',
+ headers: {'Content-Type': 'application/json'}, body: JSON.stringify({prompt_id: id, node_id: nodeId})});
+ if (!response.ok) throw new Error('move_failed');
+ const reply = await response.json();
+ if (reply.status === 'unavailable') throw new Error('move_failed');
+ await refresh();
+ return reply;
+ }
async function submit(session, randomized) {
let seed = session.snapshot.output[nodeId].inputs.seed;
if (randomized) {
@@ -176,7 +186,8 @@ export function createStudioQueue(api, nodeId, {random = randomSeed, pollMs = 20
if (!response.ok) throw new Error('queue_unavailable');
const queue = await response.json();
running = (queue.queue_running || []).filter(matches).map(entry)[0] || null;
- pending = (queue.queue_pending || []).filter(matches).map(entry);
+ // Comfy returns its heap array; the queue number gives the real running order.
+ pending = (queue.queue_pending || []).filter(matches).sort((a, b) => a[0] - b[0]).map(entry);
for (const row of [running, ...pending]) if (row) remember(row.id);
await advanceLoop(); publish();
}
@@ -223,7 +234,7 @@ export function createStudioQueue(api, nodeId, {random = randomSeed, pollMs = 20
api.addEventListener('execution_interrupted', onFailure);
api.addEventListener('executed', onExecuted);
return {
- state, refresh, start, stopLoop,
+ state, refresh, start, stopLoop, moveFirst,
subscribe(listener) { listeners.add(listener); listener(state()); schedule(); return () => { listeners.delete(listener); schedule(); }; },
async cancel(id) {
if (loop?.waiting === id) { loop.active = false; publish(); }