Skip to content

Commit a0e4603

Browse files
Andrea Falzettiakosyakovfelladrin
authored andcommitted
jetbrains: run warmup as last task
Co-authored-by: Anton Kosyakov <[email protected]> Co-authored-by: Victor Nogueira <[email protected]>
1 parent 02971af commit a0e4603

8 files changed

+71
-7
lines changed

components/ide-service/BUILD.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ packages:
3535
scripts:
3636
- name: gen-golden-files
3737
script: |
38-
go test -timeout 30s -run ^TestResolveWorkspaceConfig$ github.com/gitpod-io/gitpod/ide-service/pkg/server --force --update
38+
go test -timeout 30s -run ./... github.com/gitpod-io/gitpod/ide-service/pkg/server --force --update

components/ide-service/pkg/server/testdata/ideconfig_happypath.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@
9090
}
9191
},
9292
"Err": ""
93-
}
93+
}

components/ide-service/pkg/server/testdata/ideconfig_happypath_resolve.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@
9292
}
9393
},
9494
"Err": ""
95-
}
95+
}

components/ide-service/pkg/server/testdata/ideconfig_idetype_not_correct.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
}
1010
},
1111
"Err": "invalid ide config: DefaultDesktopIde should be desktop but browser"
12-
}
12+
}

components/ide-service/pkg/server/testdata/ideconfig_idetype_unknown.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
}
1010
},
1111
"Err": "invalid ide config"
12-
}
12+
}

components/ide-service/pkg/server/testdata/resolve_ws_config_referrer_invalid.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
"web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9"
55
},
66
"Err": ""
7-
}
7+
}

components/ide-service/pkg/server/testdata/resolve_ws_config_regular_code.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
"web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9"
1111
},
1212
"Err": ""
13-
}
13+
}

components/ide/jetbrains/launcher/main.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func main() {
161161
}
162162

163163
if launchCtx.warmup {
164+
waitForTasksToFinish()
164165
launch(launchCtx)
165166
return
166167
}
@@ -866,3 +867,66 @@ func resolveProjectContextDir(launchCtx *LaunchContext) string {
866867

867868
return launchCtx.projectDir
868869
}
870+
871+
func waitForTasksToFinish() {
872+
ctx, cancel := context.WithCancel(context.Background())
873+
defer cancel()
874+
875+
var conn *grpc.ClientConn
876+
var err error
877+
878+
for {
879+
conn, err = dial(ctx)
880+
if err == nil {
881+
err = checkTasks(ctx, conn)
882+
}
883+
884+
if err == nil {
885+
return
886+
}
887+
888+
log.WithError(err).Error("launcher: failed to check tasks status")
889+
890+
select {
891+
case <-ctx.Done():
892+
return
893+
case <-time.After(1 * time.Second):
894+
}
895+
}
896+
}
897+
898+
func checkTasks(ctx context.Context, conn *grpc.ClientConn) error {
899+
client := supervisor.NewStatusServiceClient(conn)
900+
tasksResponse, err := client.TasksStatus(ctx, &supervisor.TasksStatusRequest{Observe: true})
901+
if err != nil {
902+
return xerrors.Errorf("failed get tasks status client: %w", err)
903+
}
904+
905+
for {
906+
var runningTasksCounter int
907+
908+
resp, err := tasksResponse.Recv()
909+
if err != nil {
910+
return err
911+
}
912+
913+
for _, task := range resp.Tasks {
914+
if task.State != supervisor.TaskState_closed && task.Presentation.Name != "GITPOD_JB_WARMUP_TASK" {
915+
runningTasksCounter++
916+
}
917+
}
918+
if runningTasksCounter == 0 {
919+
break
920+
}
921+
}
922+
923+
return nil
924+
}
925+
926+
func dial(ctx context.Context) (*grpc.ClientConn, error) {
927+
supervisorConn, err := grpc.DialContext(ctx, util.GetSupervisorAddress(), grpc.WithTransportCredentials(insecure.NewCredentials()))
928+
if err != nil {
929+
err = xerrors.Errorf("failed connecting to supervisor: %w", err)
930+
}
931+
return supervisorConn, err
932+
}

0 commit comments

Comments
 (0)