MCPcopy Create free account
hub / github.com/FrodeHus/EntraRoleReaper / JobQueue

Function JobQueue

web/src/app/JobQueue.tsx:20–224  ·  view source on GitHub ↗
({
  accessToken,
  onOpenResult,
  collapsible = true,
  defaultCollapsed = true,
  title = "Job queue",
  onInProgressChange,
}: {
  accessToken: string | null;
  onOpenResult?: (id: string) => void;
  collapsible?: boolean;
  defaultCollapsed?: boolean;
  title?: string;
  onInProgressChange?: (inProgress: boolean) => void;
})

Source from the content-addressed store, hash-verified

18};
19
20export function JobQueue({
21 accessToken,
22 onOpenResult,
23 collapsible = true,
24 defaultCollapsed = true,
25 title = "Job queue",
26 onInProgressChange,
27}: {
28 accessToken: string | null;
29 onOpenResult?: (id: string) => void;
30 collapsible?: boolean;
31 defaultCollapsed?: boolean;
32 title?: string;
33 onInProgressChange?: (inProgress: boolean) => void;
34}) {
35 const [jobs, setJobs] = useState<Job[]>([]);
36 const [loading, setLoading] = useState(false);
37
38 const refresh = async () => {
39 if (!accessToken) return;
40 try {
41 setLoading(true);
42 const url = new URL("/api/review/jobs", import.meta.env.VITE_API_URL);
43 const res = await fetch(url, {
44 headers: { Authorization: `Bearer ${accessToken}` },
45 });
46 if (!res.ok) return;
47 const json = await res.json();
48 setJobs(json as Job[]);
49 } finally {
50 setLoading(false);
51 }
52 };
53
54 useEffect(() => {
55 if (!accessToken) return;
56 // Single refresh on mount/token change
57 void refresh();
58 }, [accessToken]);
59
60 // Notify parent when any job is queued or running
61 useEffect(() => {
62 const anyInProgress = jobs.some(
63 (j) => j.status === "Queued" || j.status === "Running"
64 );
65 onInProgressChange?.(anyInProgress);
66 }, [jobs, onInProgressChange]);
67
68 // (count callback removed)
69
70 const canCancel = (j: Job) => j.status === "Queued";
71
72 const cancel = async (id: string) => {
73 if (!accessToken) return;
74 const url = new URL(
75 `/api/review/${id}/cancel`,
76 import.meta.env.VITE_API_URL
77 );

Callers

nothing calls this directly

Calls 4

refreshFunction · 0.85
tickFunction · 0.85
canCancelFunction · 0.85
cancelFunction · 0.85

Tested by

no test coverage detected