Add job status endpoint, persist lastJobId; replace in-process queue with BullMQ-based queue and worker; link job status in UI

This commit is contained in:
2026-05-16 14:28:34 +02:00
parent d9f9150d68
commit 3234a09096
6 changed files with 174 additions and 4 deletions
+14 -2
View File
@@ -62,8 +62,20 @@ export default function MostActiveStocks() {
const data = await res.json().catch(() => null);
throw new Error(data?.error || "Failed to save stock");
}
// trigger analysis in background (non-blocking)
fetch(`/api/analyze`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ticker: symbol, background: true }) }).catch(() => {});
// trigger analysis in background (non-blocking) and persist jobId to stock record
try {
const analyzeRes = await fetch(`/api/analyze`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ticker: symbol, background: true }) });
const analyzeData = await analyzeRes.json().catch(() => null);
if (analyzeRes.ok && analyzeData?.jobId) {
const fd = new FormData();
fd.append("ticker", symbol);
fd.append("lastJobId", analyzeData.jobId.toString());
await fetch("/api/stocks", { method: "POST", body: fd });
setSaved((p) => ({ ...p, [symbol]: true }));
}
} catch (err) {
console.warn("Failed to enqueue background analyze:", err);
}
setSaved((p) => ({ ...p, [symbol]: true }));
} catch (err) {
console.error(err);