Skip to content

Commit 8f432a9

Browse files
committed
Wait for content ready before launching IDE
1 parent 2282a1d commit 8f432a9

File tree

3 files changed

+22
-33
lines changed

3 files changed

+22
-33
lines changed

components/ide/code/codehelper/main.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,11 @@ func main() {
4141
log.Init(ServiceName, Version, true, false)
4242
startTime := time.Now()
4343

44-
log.Info("wait until content available")
45-
46-
// wait until content ready
47-
contentStatus, wsInfo, err := resolveWorkspaceInfo(context.Background())
48-
if err != nil || wsInfo == nil || contentStatus == nil || !contentStatus.Available {
49-
log.WithError(err).WithField("wsInfo", wsInfo).WithField("cstate", contentStatus).Error("resolve workspace info failed")
44+
wsInfo, err := resolveWorkspaceInfo(context.Background())
45+
if err != nil || wsInfo == nil {
46+
log.WithError(err).WithField("wsInfo", wsInfo).Error("resolve workspace info failed")
5047
return
5148
}
52-
log.WithField("cost", time.Now().Local().Sub(startTime).Milliseconds()).Info("content available")
5349

5450
// code server args install extension with id
5551
args := []string{}
@@ -117,8 +113,8 @@ func main() {
117113
}
118114
}
119115

120-
func resolveWorkspaceInfo(ctx context.Context) (*supervisor.ContentStatusResponse, *supervisor.WorkspaceInfoResponse, error) {
121-
resolve := func(ctx context.Context) (contentStatus *supervisor.ContentStatusResponse, wsInfo *supervisor.WorkspaceInfoResponse, err error) {
116+
func resolveWorkspaceInfo(ctx context.Context) (*supervisor.WorkspaceInfoResponse, error) {
117+
resolve := func(ctx context.Context) (wsInfo *supervisor.WorkspaceInfoResponse, err error) {
122118
supervisorAddr := os.Getenv("SUPERVISOR_ADDR")
123119
if supervisorAddr == "" {
124120
supervisorAddr = "localhost:22999"
@@ -133,22 +129,18 @@ func resolveWorkspaceInfo(ctx context.Context) (*supervisor.ContentStatusRespons
133129
err = errors.New("get workspace info failed: " + err.Error())
134130
return
135131
}
136-
contentStatus, err = supervisor.NewStatusServiceClient(supervisorConn).ContentStatus(ctx, &supervisor.ContentStatusRequest{Wait: true})
137-
if err != nil {
138-
err = errors.New("get content available failed: " + err.Error())
139-
}
140132
return
141133
}
142134
// try resolve workspace info 10 times
143135
for attempt := 0; attempt < 10; attempt++ {
144-
if contentStatus, wsInfo, err := resolve(ctx); err != nil {
136+
if wsInfo, err := resolve(ctx); err != nil {
145137
log.WithError(err).Error("resolve workspace info failed")
146138
time.Sleep(1 * time.Second)
147139
} else {
148-
return contentStatus, wsInfo, err
140+
return wsInfo, err
149141
}
150142
}
151-
return nil, nil, errors.New("failed with attempt 10 times")
143+
return nil, errors.New("failed with attempt 10 times")
152144
}
153145

154146
type Extension struct {

components/ide/jetbrains/image/status/main.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,11 @@ func main() {
6868
return
6969
}
7070

71-
// wait until content ready
72-
contentStatus, wsInfo, err := resolveWorkspaceInfo(context.Background())
73-
if err != nil || wsInfo == nil || contentStatus == nil || !contentStatus.Available {
74-
log.WithError(err).WithField("wsInfo", wsInfo).WithField("cstate", contentStatus).Error("resolve workspace info failed")
71+
wsInfo, err := resolveWorkspaceInfo(context.Background())
72+
if err != nil || wsInfo == nil {
73+
log.WithError(err).WithField("wsInfo", wsInfo).Error("resolve workspace info failed")
7574
return
7675
}
77-
log.WithField("cost", time.Now().Local().Sub(startTime).Milliseconds()).Info("content available")
7876

7977
repoRoot := wsInfo.GetCheckoutLocation()
8078
gitpodConfig, err := parseGitpodConfig(repoRoot)
@@ -218,8 +216,8 @@ func terminateIDE(backendPort string) error {
218216
return nil
219217
}
220218

221-
func resolveWorkspaceInfo(ctx context.Context) (*supervisor.ContentStatusResponse, *supervisor.WorkspaceInfoResponse, error) {
222-
resolve := func(ctx context.Context) (contentStatus *supervisor.ContentStatusResponse, wsInfo *supervisor.WorkspaceInfoResponse, err error) {
219+
func resolveWorkspaceInfo(ctx context.Context) (*supervisor.WorkspaceInfoResponse, error) {
220+
resolve := func(ctx context.Context) (wsInfo *supervisor.WorkspaceInfoResponse, err error) {
223221
supervisorAddr := os.Getenv("SUPERVISOR_ADDR")
224222
if supervisorAddr == "" {
225223
supervisorAddr = "localhost:22999"
@@ -234,22 +232,18 @@ func resolveWorkspaceInfo(ctx context.Context) (*supervisor.ContentStatusRespons
234232
err = errors.New("get workspace info failed: " + err.Error())
235233
return
236234
}
237-
contentStatus, err = supervisor.NewStatusServiceClient(supervisorConn).ContentStatus(ctx, &supervisor.ContentStatusRequest{Wait: true})
238-
if err != nil {
239-
err = errors.New("get content available failed: " + err.Error())
240-
}
241235
return
242236
}
243237
// try resolve workspace info 10 times
244238
for attempt := 0; attempt < 10; attempt++ {
245-
if contentStatus, wsInfo, err := resolve(ctx); err != nil {
239+
if wsInfo, err := resolve(ctx); err != nil {
246240
log.WithError(err).Error("resolve workspace info failed")
247241
time.Sleep(1 * time.Second)
248242
} else {
249-
return contentStatus, wsInfo, err
243+
return wsInfo, err
250244
}
251245
}
252-
return nil, nil, errors.New("failed with attempt 10 times")
246+
return nil, errors.New("failed with attempt 10 times")
253247
}
254248

255249
func run(wsInfo *supervisor.WorkspaceInfoResponse, alias string) {

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,10 @@ func Run(options ...RunOption) {
306306

307307
var ideWG sync.WaitGroup
308308
ideWG.Add(1)
309-
go startAndWatchIDE(ctx, cfg, &cfg.IDE, childProcEnvvars, &ideWG, ideReady, WebIDE)
309+
go startAndWatchIDE(ctx, cfg, &cfg.IDE, childProcEnvvars, &ideWG, cstate, ideReady, WebIDE)
310310
if cfg.DesktopIDE != nil {
311311
ideWG.Add(1)
312-
go startAndWatchIDE(ctx, cfg, cfg.DesktopIDE, childProcEnvvars, &ideWG, desktopIdeReady, DesktopIDE)
312+
go startAndWatchIDE(ctx, cfg, cfg.DesktopIDE, childProcEnvvars, &ideWG, cstate, desktopIdeReady, DesktopIDE)
313313
}
314314

315315
var (
@@ -725,7 +725,7 @@ var (
725725
errSignalTerminated = errors.New("signal: terminated")
726726
)
727727

728-
func startAndWatchIDE(ctx context.Context, cfg *Config, ideConfig *IDEConfig, childProcEnvvars []string, wg *sync.WaitGroup, ideReady *ideReadyState, ide IDEKind) {
728+
func startAndWatchIDE(ctx context.Context, cfg *Config, ideConfig *IDEConfig, childProcEnvvars []string, wg *sync.WaitGroup, cstate *InMemoryContentState, ideReady *ideReadyState, ide IDEKind) {
729729
defer wg.Done()
730730
defer log.WithField("ide", ide.String()).Debug("startAndWatchIDE shutdown")
731731

@@ -734,6 +734,9 @@ func startAndWatchIDE(ctx context.Context, cfg *Config, ideConfig *IDEConfig, ch
734734
return
735735
}
736736

737+
// Wait until content ready to launch IDE
738+
<-cstate.ContentReady()
739+
737740
ideStatus := statusNeverRan
738741

739742
var (

0 commit comments

Comments
 (0)