@@ -462,39 +462,28 @@ interface RunningPrebuildViewProps {
462
462
463
463
function RunningPrebuildView ( props : RunningPrebuildViewProps ) {
464
464
const [ logsEmitter ] = useState ( new EventEmitter ( ) ) ;
465
- const [ pollTimeout , setPollTimeout ] = useState < NodeJS . Timeout | undefined > ( ) ;
466
- const [ prebuildDoneTriggered , setPrebuildDoneTriggered ] = useState < boolean > ( false ) ;
467
465
468
466
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
-
491
467
const disposables = watchHeadlessLogs (
492
468
props . runningPrebuild . instanceID ,
493
469
( chunk ) => logsEmitter . emit ( "logs" , chunk ) ,
494
- checkIsPrebuildDone ,
470
+ async ( ) => false ,
495
471
) ;
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
+
496
486
return function cleanup ( ) {
497
- clearTimeout ( pollTimeout ! ) ;
498
487
disposables . dispose ( ) ;
499
488
} ;
500
489
} , [ ] ) ;
@@ -507,7 +496,6 @@ function RunningPrebuildView(props: RunningPrebuildViewProps) {
507
496
< button
508
497
className = "mt-6 secondary"
509
498
onClick = { ( ) => {
510
- clearTimeout ( pollTimeout ! ) ;
511
499
props . onIgnorePrebuild ( ) ;
512
500
} }
513
501
>
0 commit comments