Last active
July 26, 2022 00:16
-
-
Save dchw/7627e82a868916b659e5425bf5438893 to your computer and use it in GitHub Desktop.
Buildkit monitorHealth with debug logs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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