Skip to content

Commit

Permalink
jetbrains: run warmup as last task
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Kosyakov <[email protected]>
Co-authored-by: Victor Nogueira <[email protected]>
  • Loading branch information
3 people committed Dec 14, 2022
1 parent 017cfbf commit fa81cea
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 214 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9"
},
"Err": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9"
},
"Err": ""
}
}
64 changes: 64 additions & 0 deletions components/ide/jetbrains/launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func main() {
}

if launchCtx.warmup {
waitForTasksToFinish()
launch(launchCtx)
return
}
Expand Down Expand Up @@ -853,3 +854,66 @@ func resolveProjectContextDir(launchCtx *LaunchContext) string {

return launchCtx.projectDir
}

func waitForTasksToFinish() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

var conn *grpc.ClientConn
var err error

for {
conn, err = dial(ctx)
if err == nil {
err = checkTasks(ctx, conn)
}

if err == nil {
return
}

log.WithError(err).Error("launcher: failed to check tasks status")

select {
case <-ctx.Done():
return
case <-time.After(1 * time.Second):
}
}
}

func checkTasks(ctx context.Context, conn *grpc.ClientConn) error {
client := supervisor.NewStatusServiceClient(conn)
tasksResponse, err := client.TasksStatus(ctx, &supervisor.TasksStatusRequest{Observe: true})
if err != nil {
return xerrors.Errorf("failed get tasks status client: %w", err)
}

for {
var runningTasksCounter int

resp, err := tasksResponse.Recv()
if err != nil {
return err
}

for _, task := range resp.Tasks {
if task.State != supervisor.TaskState_closed && task.Presentation.Name != "GITPOD_JB_WARMUP_TASK" {
runningTasksCounter++
}
}
if runningTasksCounter == 0 {
break
}
}

return nil
}

func dial(ctx context.Context) (*grpc.ClientConn, error) {
supervisorConn, err := grpc.DialContext(ctx, util.GetSupervisorAddress(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
err = xerrors.Errorf("failed connecting to supervisor: %w", err)
}
return supervisorConn, err
}

0 comments on commit fa81cea

Please sign in to comment.