set ping
This commit is contained in:
parent
b345627054
commit
cf2913b53d
@ -3,7 +3,6 @@ package repository
|
||||
import (
|
||||
"codeword/internal/models"
|
||||
"context"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||
"time"
|
||||
@ -35,6 +34,5 @@ func (r *UserRepository) GetRecoveryRecord(signature string) (*models.RestoreReq
|
||||
}
|
||||
|
||||
func (r *UserRepository) Ping(ctx context.Context) error {
|
||||
fmt.Println("Ping")
|
||||
return r.db.Client().Ping(ctx, readpref.Primary())
|
||||
}
|
||||
|
@ -4,8 +4,10 @@ import (
|
||||
controller "codeword/internal/controller/recovery"
|
||||
"codeword/internal/repository"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ServerConfig struct {
|
||||
@ -50,11 +52,17 @@ func (s *Server) handleLiveness(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
func (s *Server) handleReadiness(c *fiber.Ctx) error {
|
||||
startTime := time.Now()
|
||||
if err := s.Repo.Ping(c.Context()); err != nil {
|
||||
s.Logger.Error("Failed to ping the database", zap.Error(err))
|
||||
return c.Status(fiber.StatusServiceUnavailable).SendString("DB ping failed")
|
||||
}
|
||||
return c.Status(fiber.StatusOK).SendString("OK")
|
||||
duration := time.Since(startTime)
|
||||
|
||||
durationMillis := duration.Milliseconds()
|
||||
responseMessage := fmt.Sprintf("DB ping success - Time taken: %d ms", durationMillis)
|
||||
|
||||
return c.Status(fiber.StatusOK).SendString(responseMessage)
|
||||
}
|
||||
|
||||
func (s *Server) Start(addr string) error {
|
||||
|
Loading…
Reference in New Issue
Block a user