MCPcopy Create free account
hub / github.com/bhancockio/nextjs-crewai-basic-tutorial / fetchJobStatus

Function fetchJobStatus

nextjs_app/hooks/useCrewJob.tsx:39–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37 console.log("currentJobId", currentJobId);
38
39 const fetchJobStatus = async () => {
40 try {
41 console.log("calling fetchJobStatus");
42 const response = await axios.get<{
43 status: string;
44 result: { positions: PositionInfo[] };
45 events: EventType[];
46 }>(`http://localhost:3001/api/crew/${currentJobId}`);
47 const { status, events: fetchedEvents, result } = response.data;
48
49 console.log("status update", response.data);
50
51 setEvents(fetchedEvents);
52 if (result) {
53 console.log("setting job result", result);
54 console.log("setting job positions", result.positions);
55 setPositionInfoList(result.positions || []);
56 }
57
58 if (status === "COMPLETE" || status === "ERROR") {
59 if (intervalId) {
60 clearInterval(intervalId);
61 }
62 setRunning(false);
63 toast.success(`Job ${status.toLowerCase()}.`);
64 }
65 } catch (error) {
66 if (intervalId) {
67 clearInterval(intervalId);
68 }
69 setRunning(false);
70 toast.error("Failed to get job status.");
71 console.error(error);
72 }
73 };
74
75 if (currentJobId !== "") {
76 intervalId = setInterval(fetchJobStatus, 1000) as unknown as number;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected