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
+17
View File
@@ -0,0 +1,17 @@
import { Queue } from "bullmq";
export async function loader({ params }: { params: { jobId: string } }) {
const jobId = params.jobId;
if (!jobId) return Response.json({ error: "jobId required" }, { status: 400 });
try {
const q = new Queue("analyze", { connection: process.env.REDIS_URL ? { connection: process.env.REDIS_URL } : undefined });
const job = await q.getJob(jobId);
if (!job) return Response.json({ error: "Job not found" }, { status: 404 });
const state = await job.getState();
return Response.json({ id: job.id, state, failedReason: job.failedReason || null, returnValue: job.returnvalue || null });
} catch (err) {
console.error("/api/jobs loader error:", err);
return Response.json({ error: "internal" }, { status: 500 });
}
}
+3
View File
@@ -27,6 +27,7 @@ export async function action({ request }: { request: Request }) {
const lastDecision = formData.get("lastDecision")?.toString();
const lastExplanation = formData.get("lastExplanation")?.toString();
const lastExecutionPlan = formData.get("lastExecutionPlan")?.toString();
const lastJobId = formData.get("lastJobId")?.toString();
// Upsert the stock record so ticker is ensured and optional fields are saved
const stock = await db.stock.upsert({
@@ -35,12 +36,14 @@ export async function action({ request }: { request: Request }) {
lastDecision: lastDecision ?? undefined,
lastExplanation: lastExplanation ?? undefined,
lastExecutionPlan: lastExecutionPlan ?? undefined,
lastJobId: lastJobId ?? undefined,
},
create: {
ticker,
lastDecision: lastDecision ?? undefined,
lastExplanation: lastExplanation ?? undefined,
lastExecutionPlan: lastExecutionPlan ?? undefined,
lastJobId: lastJobId ?? undefined,
},
});