Skip to content

feat(site): display builds logs by default #11597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Close websocket when finishes
  • Loading branch information
BrunoQuaresma committed Jan 12, 2024
commit be252bd46949d31bf4073dce25b1277348b7482c
11 changes: 7 additions & 4 deletions site/src/hooks/useWorkspaceBuildLogs.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { watchBuildLogsByBuildId } from "api/api";
import { ProvisionerJobLog } from "api/typesGenerated";
import { displayError } from "components/GlobalSnackbar/utils";
import { useState, useEffect } from "react";
import { useState, useEffect, useRef } from "react";

export const useWorkspaceBuildLogs = (
// buildId is optional because sometimes the build is not loaded yet
buildId: string | undefined,
enabled: boolean = true,
) => {
const [logs, setLogs] = useState<ProvisionerJobLog[]>();
const socket = useRef<WebSocket>();

useEffect(() => {
if (!buildId || !enabled) {
socket.current?.close();
return;
}

// Every time this hook is called reset the values
setLogs(undefined);

const socket = watchBuildLogsByBuildId(buildId, {
socket.current = watchBuildLogsByBuildId(buildId, {
// Retrieve all the logs
after: -1,
onMessage: (log) => {
Expand All @@ -34,9 +37,9 @@ export const useWorkspaceBuildLogs = (
});

return () => {
socket.close();
socket.current?.close();
};
}, [buildId]);
}, [buildId, enabled]);

return logs;
};