Skip to content

Commit c5e1e01

Browse files
geroplroboquat
authored andcommitted
[dashboard] PrebuildLogs: Don't block on error
1 parent c885657 commit c5e1e01

File tree

1 file changed

+53
-38
lines changed

1 file changed

+53
-38
lines changed

components/dashboard/src/components/PrebuildLogs.tsx

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,60 +32,75 @@ export default function PrebuildLogs(props: PrebuildLogsProps) {
3232
const [logsEmitter] = useState(new EventEmitter());
3333
const [prebuild, setPrebuild] = useState<PrebuildWithStatus | undefined>();
3434

35+
function handlePrebuildUpdate(prebuild: PrebuildWithStatus) {
36+
if (prebuild.info.buildWorkspaceId === props.workspaceId) {
37+
setPrebuild(prebuild);
38+
39+
// In case the Prebuild got "aborted" or "time(d)out" we want to user to proceed anyway
40+
if (props.onIgnorePrebuild && (prebuild.status === "aborted" || prebuild.status === "timeout")) {
41+
props.onIgnorePrebuild();
42+
}
43+
// TODO(gpl) We likely want to move the "happy path" logic (for status "available")
44+
// here as well at some point. For that to work we need a "registerPrebuildUpdate(prebuildId)" API
45+
}
46+
}
47+
3548
useEffect(() => {
3649
const disposables = new DisposableCollection();
37-
setWorkspaceInstance(undefined);
3850
(async () => {
3951
if (!props.workspaceId) {
4052
return;
4153
}
54+
setWorkspaceInstance(undefined);
55+
setPrebuild(undefined);
56+
57+
// Try get hold of a recent WorkspaceInfo
4258
try {
4359
const info = await getGitpodService().server.getWorkspace(props.workspaceId);
60+
setWorkspaceInstance(info?.latestInstance);
61+
} catch (err) {
62+
console.error(err);
63+
setError(err);
64+
}
65+
66+
// Try get hold of a recent Prebuild
67+
try {
4468
const pbws = await getGitpodService().server.findPrebuildByWorkspaceID(props.workspaceId);
45-
if (info.latestInstance) {
46-
setWorkspaceInstance(info.latestInstance);
47-
}
4869
if (pbws) {
4970
const foundPrebuild = await getGitpodService().server.getPrebuild(pbws.id);
50-
setPrebuild(foundPrebuild);
71+
if (foundPrebuild) {
72+
handlePrebuildUpdate(foundPrebuild);
73+
}
5174
}
52-
disposables.push(
53-
getGitpodService().registerClient({
54-
onInstanceUpdate: (instance) => {
55-
if (props.workspaceId === instance.workspaceId) {
56-
setWorkspaceInstance(instance);
57-
}
58-
},
59-
onWorkspaceImageBuildLogs: (
60-
info: WorkspaceImageBuild.StateInfo,
61-
content?: WorkspaceImageBuild.LogContent,
62-
) => {
63-
if (!content) {
64-
return;
65-
}
66-
logsEmitter.emit("logs", content.text);
67-
},
68-
onPrebuildUpdate(update: PrebuildWithStatus) {
69-
if (update.info && update.info.buildWorkspaceId === props.workspaceId) {
70-
setPrebuild(update);
71-
72-
// In case the Prebuild got "aborted" or "time(d)out" we want to user to proceed anyway
73-
if (
74-
props.onIgnorePrebuild &&
75-
(update.status === "aborted" || update.status === "timeout")
76-
) {
77-
props.onIgnorePrebuild();
78-
}
79-
// TODO(gpl) We likely want to move the "happy path" logic (for status "available")
80-
// here as well at some point. For that to work we need a "registerPrebuildUpdate(prebuildId)" API
81-
}
82-
},
83-
}),
84-
);
8575
} catch (err) {
8676
console.error(err);
8777
setError(err);
8878
}
79+
80+
// Register for future updates
81+
disposables.push(
82+
getGitpodService().registerClient({
83+
onInstanceUpdate: (instance) => {
84+
if (props.workspaceId === instance.workspaceId) {
85+
setWorkspaceInstance(instance);
86+
}
87+
},
88+
onWorkspaceImageBuildLogs: (
89+
info: WorkspaceImageBuild.StateInfo,
90+
content?: WorkspaceImageBuild.LogContent,
91+
) => {
92+
if (!content) {
93+
return;
94+
}
95+
logsEmitter.emit("logs", content.text);
96+
},
97+
onPrebuildUpdate(update: PrebuildWithStatus) {
98+
if (update.info) {
99+
handlePrebuildUpdate(update);
100+
}
101+
},
102+
}),
103+
);
89104
})();
90105
return function cleanup() {
91106
disposables.dispose();

0 commit comments

Comments
 (0)