Dashboard: pipeline status view (Prefect flow runs + recent review actions, 30s auto-refresh); reviewed_at column

This commit is contained in:
2026-08-08 11:23:00 +10:00
parent a6d0ced949
commit 1814b5c5c4
3 changed files with 200 additions and 2 deletions

View File

@@ -132,6 +132,22 @@ def stats():
return json.dumps({"total": total, "by_status": by_status, "by_source": by_source})
@app.get("/pipeline", response_class=HTMLResponse)
def pipeline(request: Request):
"""Pipeline status: recent Prefect flow runs + recent review actions."""
import sys
if str(BASE.parent) not in sys.path:
sys.path.insert(0, str(BASE.parent))
import status_helper
runs = status_helper.get_flow_runs(limit=15)
actions = status_helper.get_recent_actions(limit=20)
return templates.TemplateResponse(
request, "pipeline.html",
{"runs": runs, "actions": actions},
)
def _set_status(sha: str, status: str, request: Request) -> HTMLResponse:
"""Update DB status ONLY — instant. File moves happen at import time."""
conn = _conn()
@@ -139,7 +155,9 @@ def _set_status(sha: str, status: str, request: Request) -> HTMLResponse:
if not row:
conn.close()
raise HTTPException(404)
conn.execute("UPDATE image_hashes SET status=? WHERE sha256=?", (status, sha))
conn.execute(
"UPDATE image_hashes SET status=?, reviewed_at=datetime('now') WHERE sha256=?",
(status, sha))
conn.commit()
row = conn.execute("SELECT * FROM image_hashes WHERE sha256=?", (sha,)).fetchone()
conn.close()
@@ -180,7 +198,9 @@ async def bulk_action(request: Request):
updated = 0
missing = 0
for sha in shas:
cur = conn.execute("UPDATE image_hashes SET status=? WHERE sha256=?", (status, sha))
cur = conn.execute(
"UPDATE image_hashes SET status=?, reviewed_at=datetime('now') WHERE sha256=?",
(status, sha))
if cur.rowcount:
updated += 1
else:

View File

@@ -0,0 +1,73 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pipeline — photo-pipeline</title>
<meta http-equiv="refresh" content="30">
<style>
:root { color-scheme: dark; }
body { font-family: system-ui, sans-serif; margin: 0; background: #111; color: #eee; }
header { padding: 1rem 1.5rem; border-bottom: 1px solid #333; display: flex; gap: 1.5rem; align-items: baseline; }
header h1 { font-size: 1.2rem; margin: 0; }
header a { color: #6cf; text-decoration: none; }
main { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }
h2 { font-size: 1.1rem; margin-top: 2rem; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .5rem .75rem; border-bottom: 1px solid #222; }
th { color: #999; font-size: .8rem; text-transform: uppercase; }
.badge { display: inline-block; padding: .15rem .5rem; border-radius: 999px; font-size: .75rem; }
.badge.completed { background: #1d4; color: #031; }
.badge.crashed, .badge.failed { background: #d43; color: #fff; }
.badge.scheduled { background: #44a; color: #fff; }
.badge.running { background: #4a4; color: #fff; }
.badge.approved { background: #1d4; color: #031; }
.badge.rejected { background: #d43; color: #fff; }
.badge.cancelled { background: #666; }
.badge.unknown { background: #333; }
.auto { color: #666; font-size: .8rem; text-align: right; margin-top: 2rem; }
</style>
</head>
<body>
<header>
<h1>📸 photo-pipeline</h1>
<a href="/">Overview</a>
<a href="/review">Review queue</a>
<a href="/pipeline">Pipeline</a>
<a href="/review?status=approved">Approved</a>
</header>
<main>
<h2>Recent flow runs (Prefect)</h2>
<table>
<tr><th>Flow</th><th>State</th><th>Run</th><th>Started</th><th>Duration</th></tr>
{% for r in runs %}
<tr>
<td>{{ r["flow"] }}</td>
<td><span class="badge {{ r["state"]|lower }}">{{ r["state"] }}</span></td>
<td style="color:#aaa">{{ r["name"] }}</td>
<td>{{ r["start"] }}</td>
<td>{{ r["duration"] }}</td>
</tr>
{% else %}
<tr><td colspan="5" style="color:#666;font-style:italic">No flow runs yet</td></tr>
{% endfor %}
</table>
<h2>Recent review actions</h2>
<table>
<tr><th>File</th><th>Decision</th><th>Source</th><th>When</th></tr>
{% for a in actions %}
<tr>
<td>{{ a["name"] }}</td>
<td><span class="badge {{ a["status"] }}">{{ a["status"] }}</span></td>
<td>{{ a["source"] }}</td>
<td>{{ a["when"] }}</td>
</tr>
{% else %}
<tr><td colspan="4" style="color:#666;font-style:italic">No review actions yet — decisions you make appear here</td></tr>
{% endfor %}
</table>
<p class="auto">Auto-refreshes every 30s.</p>
</main>
</body>
</html>