Add job queue for background analyze, enqueue from API, update MostActiveStocks form POST, add Playwright E2E for Save button
This commit is contained in:
@@ -75,33 +75,15 @@ export async function action({ request }: { request: Request }) {
|
||||
console.log("[analyze] Running trading graph...");
|
||||
|
||||
if (body.background) {
|
||||
// Run in background: start async propagation and return 202 immediately
|
||||
(async () => {
|
||||
try {
|
||||
const decision = await graph.propagate(ticker, input);
|
||||
console.log("[analyze] Background decision received:", JSON.stringify(decision));
|
||||
// persist last decision to DB
|
||||
await db.stock.upsert({
|
||||
where: { ticker },
|
||||
create: {
|
||||
ticker,
|
||||
lastDecision: decision.action as string,
|
||||
lastExplanation: (decision as any).reasoning || null,
|
||||
lastExecutionPlan: decision.executionPlan ? JSON.stringify(decision.executionPlan) : null,
|
||||
},
|
||||
update: {
|
||||
lastDecision: decision.action as string,
|
||||
lastExplanation: (decision as any).reasoning || null,
|
||||
lastExecutionPlan: decision.executionPlan ? JSON.stringify(decision.executionPlan) : null,
|
||||
},
|
||||
});
|
||||
console.log("[analyze] Background decision saved to DB for", ticker);
|
||||
} catch (bgErr) {
|
||||
console.error("[analyze] Background error:", bgErr);
|
||||
}
|
||||
})();
|
||||
|
||||
return Response.json({ status: "queued" }, { status: 202 });
|
||||
// Enqueue background analyze job and return 202 immediately
|
||||
try {
|
||||
const { enqueueAnalyze } = await import("../../lib/jobQueue");
|
||||
const jobId = enqueueAnalyze(ticker, input);
|
||||
return Response.json({ status: "queued", jobId }, { status: 202 });
|
||||
} catch (enqueueErr) {
|
||||
console.error("[analyze] enqueue error:", enqueueErr);
|
||||
return Response.json({ error: "failed to enqueue" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
const decision = await graph.propagate(ticker, input);
|
||||
|
||||
Reference in New Issue
Block a user