Improved progress status section layout

This commit is contained in:
patben8 committed 2026-10-01 10:55:09 +02:00
1 parent ecc0e4c8df
commit badf12b991
9 files changed
+154 -32

No files matched your search

+18 -1
View File
@@ -53,6 +53,13 @@ class Job:
#: library is written — so the UI can word them. Empty = unspecified.
unit: str = ""
message: str = ""
#: How far the CURRENT unit of work has got, 0..1 — so the overall bar can
#: move within a long item: at 99 % of the first of two tracks it reads
#: ~50 %, not 0. Reset whenever `done` advances.
fraction: float = 0.0
#: What the current item is doing ("separating 41 %"), shown beside its name
#: and never truncated in its place. Reset whenever `done` advances.
status: str = ""
result: Any = None
error: str | None = None
started_at: float = field(default_factory=time.time)
@@ -75,6 +82,8 @@ class Job:
"done": self.done,
"unit": self.unit,
"message": self.message,
"fraction": self.fraction,
"status": self.status,
"result": self.result,
"error": self.error,
"started_at": self.started_at,
@@ -94,11 +103,19 @@ class JobHandle:
self._job = job
def progress(self, done: int | None = None, total: int | None = None,
message: str | None = None, unit: str | None = None) -> None:
message: str | None = None, unit: str | None = None,
fraction: float | None = None, status: str | None = None) -> None:
if unit is not None:
self._job.unit = unit
if done is not None:
if done != self._job.done: # a new item: its progress starts over
self._job.fraction = 0.0
self._job.status = ""
self._job.done = done
if fraction is not None:
self._job.fraction = max(0.0, min(1.0, fraction))
if status is not None:
self._job.status = status
if total is not None:
self._job.total = total
if message is not None:
+3
View File
@@ -489,6 +489,9 @@ class JobStatus(BaseModel):
# needs to tell a byte count from a track count.
unit: str = ""
message: str
# The current item's own progress (0..1) and what it is doing — see jobs.Job.
fraction: float = 0.0
status: str = ""
result: dict | None = None
error: str | None = None
started_at: float
+28 -10
View File
@@ -39,6 +39,13 @@ _BYTES_PER_SECOND = {256_000: 5 * 256_000 / 8 * 1.03, 320_000: 5 * 320_000 / 8 *
_WORK_BYTES_PER_SECOND = 5 * 2 * 4 * sf.SR
#: Shares of ONE track's conversion time, for the status bar's within-track
#: progress (measured on the M3 Pro: decode ~1 s, separate ~50 s, encode +
#: verify ~4 s for a 4-minute track).
_DECODE_SHARE = 0.03
_SEPARATE_SHARE = 0.90
class ConvertError(Exception):
"""User-facing; refuses the whole batch."""
@@ -87,10 +94,13 @@ class Plan:
def _title(track) -> str:
"""How a track is named in progress, skip lists and reports: the track's
name FIRST — it is what tells one track from another when the end is cut
off in the status bar."""
if track is None:
return "?"
if track.artist and track.title:
return f"{track.artist} - {track.title}"
return f"{track.title} - {track.artist}"
return track.title or Path(track.filepath or "").name or track.id
@@ -229,7 +239,7 @@ def run(handle, adapter, planned: Plan, opts: Options, pending: Pending, *,
try:
for i, item in enumerate(items):
checkpoint()
handle.progress(done=i, message=item.title)
handle.progress(done=i, message=item.title, fraction=0.0, status="")
partial = partial_name(item.target)
if item.reuse is not None:
written = sf.Written(path=partial, **{k: item.reuse["written"][k] for k in ("bit_rate", "duration", "size")},
@@ -241,21 +251,29 @@ def run(handle, adapter, planned: Plan, opts: Options, pending: Pending, *,
finished.append((item, pitem, written))
continue
if engine is None:
handle.progress(message="Starting the stem engine…")
handle.progress(status="starting…")
engine = stack.enter_context(EngineProcess(mgr.executable(), mgr.weights_dir(), device=opts.device))
stack.enter_context(keep_awake(engine.proc.pid))
pitem = pending.add({"track_id": item.track_id, "mode": opts.collection, "source": str(item.source),
"stem": str(item.target), "state": "converting", "facts": source_facts(item.source)})
item.target.parent.mkdir(parents=True, exist_ok=True)
def on_progress(f: float, i=i, item=item) -> None:
handle.progress(message=f"{item.title} — separating {f * 100:.0f} %")
# Of a TRACK's time, separation is nearly all (~90 % on MPS);
# decoding before it and encoding + verifying after share the rest.
def on_progress(f: float) -> None:
frac = _DECODE_SHARE + f * (_SEPARATE_SHARE)
handle.progress(fraction=frac, status=f"separating {frac * 100:.0f} %")
def separate(pcm):
handle.progress(fraction=_DECODE_SHARE, status=f"separating {_DECODE_SHARE * 100:.0f} %")
stems = engine.separate(pcm, work, on_progress=on_progress, cancelled=lambda: handle.cancelled)
done_at = _DECODE_SHARE + _SEPARATE_SHARE
handle.progress(fraction=done_at, status=f"encoding {done_at * 100:.0f} %")
return stems
handle.progress(status="decoding 0 %")
try:
written = sf.build(item.source, partial,
lambda pcm: engine.separate(pcm, work, on_progress=on_progress,
cancelled=lambda: handle.cancelled),
checkpoint=checkpoint)
written = sf.build(item.source, partial, separate, checkpoint=checkpoint)
except (_Cancel, EngineCancelled):
partial.unlink(missing_ok=True)
pending.drop([pitem])
@@ -281,7 +299,7 @@ def run(handle, adapter, planned: Plan, opts: Options, pending: Pending, *,
finally:
shutil.rmtree(work, ignore_errors=True)
handle.progress(done=len(items), message="Swapping the converted tracks into the collection…")
handle.progress(done=len(items), message="Swapping the converted tracks into the collection…", status="")
with mutation:
if not still_current():
for _item, pitem, written in finished:
+18
View File
@@ -213,6 +213,24 @@ with tempfile.TemporaryDirectory() as d:
gate.set()
check("…and returns once it has finished", main.JOBS.wait(first.id, timeout=5) is True)
# Within-item progress: what lets the overall bar move inside a long
# track (99 % of the first of two = ~50 %), and it starts over per item.
from konduktor.jobs import Job, JobHandle
j = Job(id="x", kind="t")
h = JobHandle(j)
h.progress(done=0, total=2, fraction=0.99, status="separating 99 %")
d = j.as_dict()
check("a job reports its current item's fraction and status",
d["fraction"] == 0.99 and d["status"] == "separating 99 %", str(d))
h.progress(done=1)
check("…both reset when the next item starts", j.fraction == 0.0 and j.status == "")
h.progress(fraction=1.7)
check("…and the fraction is clamped to 0..1", j.fraction == 1.0)
from konduktor.schemas import JobStatus
r = JobStatus(**j.as_dict()).model_dump()
check("the job's response model carries fraction and status (not silently dropped)",
r["fraction"] == 1.0 and "status" in r, str(r)[:200])
check("nothing was written to disk (edits stay in memory until Save)",
work.read_bytes() == REAL.read_bytes())
+1 -1
View File
@@ -202,7 +202,7 @@ with TestClient(main.app) as c:
os.environ["FAKE_DELAY"] = "0.15"
jid = c.post("/api/tracks/stems/convert", json={"track_ids": ids, "mode": "replace"}).json()["id"]
end = time.time() + 30
while time.time() < end and "separating" not in c.get(f"/api/jobs/{jid}").json()["message"]:
while time.time() < end and "separating" not in c.get(f"/api/jobs/{jid}").json()["status"]:
time.sleep(0.05)
time.sleep(1.8) # into the second track
c.post(f"/api/jobs/{jid}/cancel")