Skip to content

Commit

Permalink
fix healthmap
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanmehrotra committed Jul 5, 2024
1 parent f9e1de6 commit af8086c
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions pkg/gofr/container/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *Container) Health(ctx context.Context) interface{} {
healthMap["pubsub"] = health
}

downCount, healthMap = checkExternalDBHealth(ctx, c, downCount, healthMap)
downCount = downCount + checkExternalDBHealth(ctx, c, healthMap)

for name, svc := range c.Services {
health := svc.HealthCheck(ctx)
Expand All @@ -56,39 +56,35 @@ func (c *Container) Health(ctx context.Context) interface{} {
return healthMap
}

func checkExternalDBHealth(ctx context.Context, c *Container, downCount int,
healthMap map[string]interface{}) (updatedDownCount int, updatedHealthMap map[string]interface{}) {
updatedDownCount = downCount
updatedHealthMap = healthMap

func checkExternalDBHealth(ctx context.Context, c *Container, healthMap map[string]interface{}) (downCount int) {
if !isNil(c.Mongo) {
health, err := c.Mongo.HealthCheck(ctx)
if err != nil {
updatedDownCount++
downCount++
}

updatedHealthMap["mongo"] = health
healthMap["mongo"] = health
}

if !isNil(c.Cassandra) {
health, err := c.Cassandra.HealthCheck(ctx)
if err != nil {
updatedDownCount++
downCount++
}

updatedHealthMap["cassandra"] = health
healthMap["cassandra"] = health
}

if !isNil(c.Clickhouse) {
health, err := c.Clickhouse.HealthCheck(ctx)
if err != nil {
updatedDownCount++
downCount++
}

updatedHealthMap["clickHouse"] = health
healthMap["clickHouse"] = health
}

return updatedDownCount, updatedHealthMap
return downCount
}

func (c *Container) appHealth(healthMap map[string]interface{}, downCount int) {
Expand Down

0 comments on commit af8086c

Please sign in to comment.