Skip to content

Instantly share code, notes, and snippets.

@dchw
Last active July 26, 2022 00:16
Show Gist options
  • Save dchw/7627e82a868916b659e5425bf5438893 to your computer and use it in GitHub Desktop.
Save dchw/7627e82a868916b659e5425bf5438893 to your computer and use it in GitHub Desktop.
Buildkit monitorHealth with debug logs
func monitorHealth(ctx context.Context, cc *grpc.ClientConn, cancelConn func()) {
defer cancelConn()
defer cc.Close()
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
healthClient := grpc_health_v1.NewHealthClient(cc)
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
fmt.Println("--- healthcheck start")
resp, err := healthClient.Check(ctx, &grpc_health_v1.HealthCheckRequest{})
fmt.Printf("--- healthcheck status: %v\n", resp.Status.String())
cancel()
if err != nil {
fmt.Println("--- healthcheck failed")
fmt.Println("--- healthcheck error: %s\n", err.Error())
return
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment