fix(diarization-ui): jobs page server-side fallback list + robust live refresh/status
This commit is contained in:
50
app.py
50
app.py
@@ -769,12 +769,19 @@ def jobs_delete(job_id: int):
|
|||||||
|
|
||||||
@app.get("/jobs", response_class=HTMLResponse)
|
@app.get("/jobs", response_class=HTMLResponse)
|
||||||
def jobs_page(queued: Optional[int] = None):
|
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 ""
|
notice = f"<p><b>Job #{queued} wurde eingereiht.</b></p>" if queued else ""
|
||||||
body = f"""
|
body = f"""
|
||||||
<h2>Hintergrundverarbeitung</h2>
|
<h2>Hintergrundverarbeitung</h2>
|
||||||
<p class='hint'>Maximal 2 Jobs gleichzeitig. Seite aktualisiert automatisch.</p>
|
<p class='hint'>Maximal 2 Jobs gleichzeitig. Seite aktualisiert automatisch.</p>
|
||||||
{notice}
|
{notice}
|
||||||
<div id='jobs-root'></div>
|
<div id='jobs-status' class='hint'>Live-Update aktiv …</div>
|
||||||
|
<div id='jobs-root'>{pre}</div>
|
||||||
<script>
|
<script>
|
||||||
function since(ts) {{
|
function since(ts) {{
|
||||||
if(!ts) return '-';
|
if(!ts) return '-';
|
||||||
@@ -788,24 +795,29 @@ async function post(url) {{
|
|||||||
if(!r.ok) alert('Fehler '+r.status);
|
if(!r.ok) alert('Fehler '+r.status);
|
||||||
}}
|
}}
|
||||||
async function renderJobs() {{
|
async function renderJobs() {{
|
||||||
const r = await fetch('/jobs/data');
|
try {{
|
||||||
const j = await r.json();
|
const r = await fetch('/jobs/data');
|
||||||
const root = document.getElementById('jobs-root');
|
const j = await r.json();
|
||||||
root.innerHTML = '';
|
const root = document.getElementById('jobs-root');
|
||||||
if(!j.items.length) {{ root.innerHTML = '<p>Keine Jobs.</p>'; return; }}
|
root.innerHTML = '';
|
||||||
for(const it of j.items) {{
|
if(!j.items.length) {{ root.innerHTML = '<p>Keine Jobs.</p>'; return; }}
|
||||||
const d = document.createElement('div'); d.className='card';
|
for(const it of j.items) {{
|
||||||
const actions = [];
|
const d = document.createElement('div'); d.className='card';
|
||||||
if(!['done','error','cancelled'].includes(it.status)) actions.push("<a href='#' class='iconbtn' onclick=\"cancelJob("+it.id+");return false;\">⛔</a>");
|
const actions = [];
|
||||||
actions.push("<a href='#' class='iconbtn' onclick=\"deleteJob("+it.id+");return false;\">🗑️</a>");
|
if(!['done','error','cancelled'].includes(it.status)) actions.push("<a href='#' class='iconbtn' onclick=\"cancelJob("+it.id+");return false;\">⛔</a>");
|
||||||
const result = it.result_document_id ? ("<a href='/document/"+it.result_document_id+"'>Ergebnis öffnen</a>") : '';
|
actions.push("<a href='#' class='iconbtn' onclick=\"deleteJob("+it.id+");return false;\">🗑️</a>");
|
||||||
const err = it.error ? ("<pre>"+String(it.error).replaceAll('<','<')+"</pre>") : '';
|
const result = it.result_document_id ? ("<a href='/document/"+it.result_document_id+"'>Ergebnis öffnen</a>") : '';
|
||||||
d.innerHTML = "<b>Job #"+it.id+"</b> ["+it.kind+"] · <b>"+it.status+"</b> · läuft: "+since(it.started_at || it.created_at)+"<br><small>"+it.created_at+"</small><br>"
|
const err = it.error ? ("<pre>"+String(it.error).replaceAll('<','<')+"</pre>") : '';
|
||||||
+(it.project_name?('Projekt: '+it.project_name+'<br>'):'')
|
d.innerHTML = "<b>Job #"+it.id+"</b> ["+it.kind+"] · <b>"+it.status+"</b> · läuft: "+since(it.started_at || it.created_at)+"<br><small>"+it.created_at+"</small><br>"
|
||||||
+(it.document_title?('Dokument: '+it.document_title+'<br>'):'')
|
+(it.project_name?('Projekt: '+it.project_name+'<br>'):'')
|
||||||
+(it.prompt_name?('Prompt: '+it.prompt_name+'<br>'):'')
|
+(it.document_title?('Dokument: '+it.document_title+'<br>'):'')
|
||||||
+"<div class='row' style='margin-top:8px'>"+actions.join(' ')+" "+result+"</div>"+err;
|
+(it.prompt_name?('Prompt: '+it.prompt_name+'<br>'):'')
|
||||||
root.appendChild(d);
|
+"<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 cancelJob(id) {{ if(!confirm('Job abbrechen?')) return; await post('/jobs/'+id+'/cancel'); renderJobs(); }}
|
||||||
|
|||||||
Reference in New Issue
Block a user