Fix timeouts
This commit is contained in:
69
app/app.py
69
app/app.py
@@ -1,5 +1,6 @@
|
||||
from flask import Flask, request, redirect
|
||||
import os, json, requests
|
||||
import os, json, time, requests
|
||||
from pathlib import Path
|
||||
from redis import Redis
|
||||
from rq import Queue
|
||||
|
||||
@@ -8,6 +9,7 @@ MEILI_KEY = os.getenv("MEILI_KEY", "") # from .env
|
||||
REDIS_URL = os.getenv("REDIS_URL", "redis://redis:6379/0")
|
||||
|
||||
app = Flask(__name__)
|
||||
FEED_LOG = Path(os.getenv("TRANSCRIPT_ROOT", "/transcripts")) / "_feed.log"
|
||||
q = Queue(connection=Redis.from_url(REDIS_URL))
|
||||
|
||||
PAGE = """
|
||||
@@ -64,9 +66,74 @@ doSearch();
|
||||
setTimeout(poll, 4000);
|
||||
})();
|
||||
</script>
|
||||
|
||||
<div style="margin-top:1rem;padding:1rem;border:1px solid #ddd;border-radius:8px;">
|
||||
<h3 style="margin-top:0;">Activity</h3>
|
||||
<div id="status-summary" style="font-family:system-ui, sans-serif; font-size:14px; margin-bottom:0.5rem;">Loading…</div>
|
||||
<pre id="status-feed" style="max-height:300px; overflow:auto; background:#f8f9fa; padding:0.5rem; border-radius:6px; border:1px solid #eee;"></pre>
|
||||
</div>
|
||||
<script>
|
||||
(async function(){
|
||||
const feed = document.getElementById('status-feed');
|
||||
const sum = document.getElementById('status-summary');
|
||||
async function tick(){
|
||||
try{
|
||||
const r = await fetch('/api/status');
|
||||
const j = await r.json();
|
||||
if(!j.ok) throw new Error('not ok');
|
||||
const ev = j.events || [];
|
||||
const last = j.summary || {};
|
||||
sum.textContent = last.last_status ? `${last.last_status} — ${last.last_title||''}` : 'Idle';
|
||||
feed.textContent = ev.map(e => {
|
||||
const s = e.status || '';
|
||||
const u = e.url || e.path || e.title || '';
|
||||
const up = e.uploader ? ` [${e.uploader}]` : '';
|
||||
return `${s.padEnd(14)} ${u}${up}`;
|
||||
}).join('\\n');
|
||||
}catch(e){
|
||||
sum.textContent = 'Status unavailable';
|
||||
}
|
||||
}
|
||||
tick();
|
||||
setInterval(tick, 2000);
|
||||
})();
|
||||
</script>
|
||||
</body></html>
|
||||
"""
|
||||
|
||||
def read_feed_tail(max_lines: int = 200):
|
||||
if not FEED_LOG.exists():
|
||||
return []
|
||||
try:
|
||||
with open(FEED_LOG, "rb") as f:
|
||||
try:
|
||||
f.seek(-65536, 2) # read last ~64KB
|
||||
except OSError:
|
||||
f.seek(0)
|
||||
data = f.read().decode("utf-8", errors="ignore")
|
||||
except Exception:
|
||||
return []
|
||||
lines = [x.strip() for x in data.splitlines() if x.strip()]
|
||||
events = []
|
||||
for ln in lines[-max_lines:]:
|
||||
try:
|
||||
events.append(json.loads(ln))
|
||||
except Exception:
|
||||
pass
|
||||
return events
|
||||
|
||||
@app.get("/api/status")
|
||||
def api_status():
|
||||
events = read_feed_tail(200)
|
||||
last = events[-1] if events else {}
|
||||
summary = {
|
||||
"last_status": last.get("status"),
|
||||
"last_title": last.get("title") or last.get("path") or last.get("url"),
|
||||
"last_time": int(time.time()),
|
||||
"count": len(events),
|
||||
}
|
||||
return {"ok": True, "summary": summary, "events": events}
|
||||
|
||||
def meili_search(qstr, limit=30):
|
||||
if not qstr.strip():
|
||||
return []
|
||||
|
Reference in New Issue
Block a user