From b2e59d8aa171041c55880229ba6b1e5d41c39df7 Mon Sep 17 00:00:00 2001 From: Froidefond Julien Date: Tue, 24 Mar 2026 21:19:47 +0100 Subject: [PATCH] fix: refresh jobs list immediately after replay Add /api/jobs/list endpoint and fetch the updated list right after a successful replay so the new job appears instantly instead of waiting for the next SSE poll (up to 15s when idle). Co-Authored-By: Claude Opus 4.6 --- apps/backoffice/app/api/jobs/list/route.ts | 11 +++++++++++ apps/backoffice/app/components/JobsList.tsx | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 apps/backoffice/app/api/jobs/list/route.ts diff --git a/apps/backoffice/app/api/jobs/list/route.ts b/apps/backoffice/app/api/jobs/list/route.ts new file mode 100644 index 0000000..7bf103f --- /dev/null +++ b/apps/backoffice/app/api/jobs/list/route.ts @@ -0,0 +1,11 @@ +import { NextResponse } from "next/server"; +import { listJobs } from "@/lib/api"; + +export async function GET() { + try { + const data = await listJobs(); + return NextResponse.json(data); + } catch (error) { + return NextResponse.json({ error: "Failed to fetch jobs" }, { status: 500 }); + } +} diff --git a/apps/backoffice/app/components/JobsList.tsx b/apps/backoffice/app/components/JobsList.tsx index 1f3bb46..91a5c50 100644 --- a/apps/backoffice/app/components/JobsList.tsx +++ b/apps/backoffice/app/components/JobsList.tsx @@ -95,9 +95,21 @@ export function JobsList({ initialJobs, libraries, highlightJobId }: JobsListPro } }; + const refreshJobs = async () => { + try { + const res = await fetch("/api/jobs/list"); + if (res.ok) { + const data = await res.json(); + if (Array.isArray(data)) setJobs(data); + } + } catch { /* SSE will catch up */ } + }; + const handleReplay = async (id: string) => { const response = await fetch(`/api/jobs/${id}/replay`, { method: "POST" }); - if (!response.ok) { + if (response.ok) { + await refreshJobs(); + } else { const data = await response.json().catch(() => ({})); console.error("Failed to replay job:", data?.error ?? response.status); }