File tree 1 file changed +20
-9
lines changed
packages/orchestrator/internal/server
1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,10 @@ func (h *Healthcheck) Start(ctx context.Context, listener net.Listener) {
81
81
}
82
82
}
83
83
84
+ // report updates the health status.
85
+ // This function is run in a goroutine every healthcheckFrequency for the reason of having
86
+ // longer running tasks that might me too slow or resource intensive to be run
87
+ // in the healthcheck http handler directly.
84
88
func (h * Healthcheck ) report (ctx context.Context ) error {
85
89
h .mu .Lock ()
86
90
defer h .mu .Unlock ()
@@ -91,25 +95,32 @@ func (h *Healthcheck) report(ctx context.Context) error {
91
95
// Update last run on report
92
96
h .lastRun = time .Now ()
93
97
94
- // Report health
95
- c , err := h .grpcHealth .Check (childCtx , & healthpb.HealthCheckRequest {
98
+ // Report health of the gRPC
99
+ var err error
100
+ h .status , err = h .getGRPCHealth (childCtx )
101
+ if err != nil {
102
+ return err
103
+ }
104
+
105
+ return nil
106
+ }
107
+
108
+ // getGRPCHealth returns the health status of the grpc.Server by calling the health service check.
109
+ func (h * Healthcheck ) getGRPCHealth (ctx context.Context ) (Status , error ) {
110
+ c , err := h .grpcHealth .Check (ctx , & healthpb.HealthCheckRequest {
96
111
// Empty string is the default service name
97
112
Service : "" ,
98
113
})
99
114
if err != nil {
100
- h .status = Unhealthy
101
-
102
- return err
115
+ return Unhealthy , err
103
116
}
104
117
105
118
switch c .GetStatus () {
106
119
case healthpb .HealthCheckResponse_SERVING :
107
- h . status = Healthy
120
+ return Healthy , nil
108
121
default :
109
- h . status = Unhealthy
122
+ return Unhealthy , nil
110
123
}
111
-
112
- return nil
113
124
}
114
125
115
126
type HealthResponse struct {
You can’t perform that action at this time.
0 commit comments