fix(diarization-ui): jobs page server-side fallback list + robust live refresh/status
This commit is contained in:
14
app.py
14
app.py
@@ -769,12 +769,19 @@ def jobs_delete(job_id: int):
|
||||
|
||||
@app.get("/jobs", response_class=HTMLResponse)
|
||||
def jobs_page(queued: Optional[int] = None):
|
||||
items = _jobs_payload(200)
|
||||
pre = "".join([
|
||||
f"<div class='card'><b>Job #{it['id']}</b> [{it['kind']}] · <b>{it['status']}</b><br><small>{it['created_at']}</small></div>"
|
||||
for it in items
|
||||
]) or "<p>Keine Jobs.</p>"
|
||||
|
||||
notice = f"<p><b>Job #{queued} wurde eingereiht.</b></p>" if queued else ""
|
||||
body = f"""
|
||||
<h2>Hintergrundverarbeitung</h2>
|
||||
<p class='hint'>Maximal 2 Jobs gleichzeitig. Seite aktualisiert automatisch.</p>
|
||||
{notice}
|
||||
<div id='jobs-root'></div>
|
||||
<div id='jobs-status' class='hint'>Live-Update aktiv …</div>
|
||||
<div id='jobs-root'>{pre}</div>
|
||||
<script>
|
||||
function since(ts) {{
|
||||
if(!ts) return '-';
|
||||
@@ -788,6 +795,7 @@ async function post(url) {{
|
||||
if(!r.ok) alert('Fehler '+r.status);
|
||||
}}
|
||||
async function renderJobs() {{
|
||||
try {{
|
||||
const r = await fetch('/jobs/data');
|
||||
const j = await r.json();
|
||||
const root = document.getElementById('jobs-root');
|
||||
@@ -807,6 +815,10 @@ async function renderJobs() {{
|
||||
+"<div class='row' style='margin-top:8px'>"+actions.join(' ')+" "+result+"</div>"+err;
|
||||
root.appendChild(d);
|
||||
}}
|
||||
document.getElementById('jobs-status').textContent = 'Live-Update aktiv';
|
||||
}} catch(e) {{
|
||||
document.getElementById('jobs-status').textContent = 'Live-Update Fehler: '+e;
|
||||
}}
|
||||
}}
|
||||
async function cancelJob(id) {{ if(!confirm('Job abbrechen?')) return; await post('/jobs/'+id+'/cancel'); renderJobs(); }}
|
||||
async function deleteJob(id) {{ if(!confirm('Job löschen?')) return; await post('/jobs/'+id+'/delete'); renderJobs(); }}
|
||||
|
||||
Reference in New Issue
Block a user