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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user