-
Notifications
You must be signed in to change notification settings - Fork 0
/
health.go
42 lines (33 loc) · 962 Bytes
/
health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package nats
import (
"context"
"gofr.dev/pkg/gofr/datasource"
)
const (
natsBackend = "Client"
jetStreamStatusOK = "OK"
jetStreamStatusError = "Error"
jetStreamConnected = "CONNECTED"
jetStreamDisconnecting = "DISCONNECTED"
)
// Health checks the health of the NATS connection.
func (c *Client) Health() datasource.Health {
if c.connManager == nil {
return datasource.Health{
Status: datasource.StatusDown,
}
}
health := c.connManager.Health()
health.Details["backend"] = natsBackend
js, err := c.connManager.JetStream()
if err != nil {
health.Details["jetstream_enabled"] = false
health.Details["jetstream_status"] = jetStreamStatusError + ": " + err.Error()
return health
}
// Call AccountInfo() to get JetStream status
jetStreamStatus := GetJetStreamStatus(context.Background(), js)
health.Details["jetstream_enabled"] = true
health.Details["jetstream_status"] = jetStreamStatus
return health
}