@@ -653,7 +653,15 @@ type InfoService struct {
653
653
defaultWorkspaceImage string
654
654
}
655
655
656
- var infoCacheDuration = 5 * time .Second
656
+ var infoCacheDuration = 30 * time .Second
657
+
658
+ func NewInfoService (cfg * Config , cstate ContentState , gitpodService serverapi.APIInterface ) * InfoService {
659
+ svc := & InfoService {cfg : cfg , ContentState : cstate , GitpodService : gitpodService }
660
+ // it makes no sense to handle cancel here, just ignore the warning (find no way now to disable it)
661
+ ctx , _ := context .WithTimeout (context .Background (), 15 * time .Second )
662
+ go svc .getDefaultWorkspaceImage (ctx )
663
+ return svc
664
+ }
657
665
658
666
// RegisterGRPC registers the gRPC info service.
659
667
func (is * InfoService ) RegisterGRPC (srv * grpc.Server ) {
@@ -675,11 +683,10 @@ func (is *InfoService) getDefaultWorkspaceImage(ctx context.Context) string {
675
683
is .cacheMu .RUnlock ()
676
684
677
685
is .cacheMu .Lock ()
678
- defer is .cacheMu .Unlock ()
679
686
defer func () {
680
687
is .cacheTimestamp = time .Now ()
688
+ is .cacheMu .Unlock ()
681
689
}()
682
-
683
690
if time .Since (is .cacheTimestamp ) < infoCacheDuration {
684
691
return is .defaultWorkspaceImage
685
692
}
@@ -691,6 +698,8 @@ func (is *InfoService) getDefaultWorkspaceImage(ctx context.Context) string {
691
698
wsImage , err := is .GitpodService .GetDefaultWorkspaceImage (ctx )
692
699
if err == nil {
693
700
is .defaultWorkspaceImage = wsImage
701
+ } else {
702
+ log .WithError (err ).Error ("failed to get default workspace image" )
694
703
}
695
704
return is .defaultWorkspaceImage
696
705
}
0 commit comments