Skip to content

Commit 8a56328

Browse files
AlexTugarevroboquat
authored andcommitted
get rid of isPrebuildDone polling
1 parent 1b21878 commit 8a56328

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

components/dashboard/src/start/CreateWorkspace.tsx

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -462,39 +462,28 @@ interface RunningPrebuildViewProps {
462462

463463
function RunningPrebuildView(props: RunningPrebuildViewProps) {
464464
const [logsEmitter] = useState(new EventEmitter());
465-
const [pollTimeout, setPollTimeout] = useState<NodeJS.Timeout | undefined>();
466-
const [prebuildDoneTriggered, setPrebuildDoneTriggered] = useState<boolean>(false);
467465

468466
useEffect(() => {
469-
const checkIsPrebuildDone = async (): Promise<boolean> => {
470-
if (prebuildDoneTriggered) {
471-
console.debug("prebuild done already triggered, doing nothing");
472-
return true;
473-
}
474-
475-
const done = await getGitpodService().server.isPrebuildDone(props.runningPrebuild.prebuildID);
476-
if (done) {
477-
// note: this treats "done" as "available" which is not equivalent.
478-
// This works because the backend ignores prebuilds which are not "available", and happily starts a workspace as if there was no prebuild at all.
479-
setPrebuildDoneTriggered(true);
480-
props.onPrebuildSucceeded();
481-
return true;
482-
}
483-
return false;
484-
};
485-
const pollIsPrebuildDone = async () => {
486-
clearTimeout(pollTimeout!);
487-
await checkIsPrebuildDone();
488-
setPollTimeout(setTimeout(pollIsPrebuildDone, 10000));
489-
};
490-
491467
const disposables = watchHeadlessLogs(
492468
props.runningPrebuild.instanceID,
493469
(chunk) => logsEmitter.emit("logs", chunk),
494-
checkIsPrebuildDone,
470+
async () => false,
495471
);
472+
473+
disposables.push(
474+
getGitpodService().registerClient({
475+
onInstanceUpdate: (update) => {
476+
if (update.workspaceId !== props.runningPrebuild.workspaceID) {
477+
return;
478+
}
479+
if (update.status.phase === "stopped") {
480+
props.onPrebuildSucceeded();
481+
}
482+
},
483+
}),
484+
);
485+
496486
return function cleanup() {
497-
clearTimeout(pollTimeout!);
498487
disposables.dispose();
499488
};
500489
}, []);
@@ -507,7 +496,6 @@ function RunningPrebuildView(props: RunningPrebuildViewProps) {
507496
<button
508497
className="mt-6 secondary"
509498
onClick={() => {
510-
clearTimeout(pollTimeout!);
511499
props.onIgnorePrebuild();
512500
}}
513501
>

0 commit comments

Comments
 (0)