Files
AITrader/app/routes/api/jobs/$jobId.ts
T

18 lines
783 B
TypeScript

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 });
}
}