MCPcopy Index your code
hub / github.com/coder/coder / watchBuildLogsByBuildId

Function watchBuildLogsByBuildId

site/src/api/api.ts:328–360  ·  view source on GitHub ↗
(
	buildId: string,
	{ onMessage, onDone, onError, after }: WatchBuildLogsByBuildIdOptions,
)

Source from the content-addressed store, hash-verified

326 onError?: (error: Error) => void;
327};
328export const watchBuildLogsByBuildId = (
329 buildId: string,
330 { onMessage, onDone, onError, after }: WatchBuildLogsByBuildIdOptions,
331) => {
332 const searchParams = new URLSearchParams({ follow: "true" });
333 if (after !== undefined) {
334 searchParams.append("after", after.toString());
335 }
336
337 const socket = createWebSocket(
338 `/api/v2/workspacebuilds/${buildId}/logs`,
339 searchParams,
340 );
341
342 socket.addEventListener("message", (event) =>
343 onMessage(JSON.parse(event.data) as TypesGen.ProvisionerJobLog),
344 );
345
346 socket.addEventListener("error", () => {
347 if (socket.readyState === socket.CLOSED) {
348 return;
349 }
350 onError?.(new Error("Connection for logs failed."));
351 socket.close();
352 });
353
354 socket.addEventListener("close", () => {
355 // When the socket closes, logs have finished streaming!
356 onDone?.();
357 });
358
359 return socket;
360};
361
362// This is the base header that is used for several requests. This is defined as
363// a readonly value, but only copies of it should be passed into the API calls,

Callers 1

useWorkspaceBuildLogsFunction · 0.90

Calls 4

createWebSocketFunction · 0.85
parseMethod · 0.80
addEventListenerMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected