main updated
This commit is contained in:
parent
b0c79808c1
commit
20ee14599e
@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/tuusuario/go-sync-service/internal/config"
|
||||
@ -16,25 +17,28 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Configurar zona horaria por defecto del proceso
|
||||
initTimezone()
|
||||
|
||||
// Cargar configuración
|
||||
conf, err := config.LoadConfig()
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error cargando configuración:", err)
|
||||
fmt.Println("Error cargando configuración:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Inicializar logger con configuración
|
||||
config.InitLogger(conf)
|
||||
config.Log.Info("🚀 Iniciando servicio: go-sync-service")
|
||||
config.Log.Info("Iniciando servicio: go-sync-service")
|
||||
|
||||
emailService := email.NewSMTPEmailService(conf)
|
||||
|
||||
// Conexión a Redis
|
||||
redisClient := config.GetRedisClient(conf)
|
||||
if err := redisClient.Ping(context.Background()).Err(); err != nil {
|
||||
config.Log.Fatalf("❌ Redis no disponible: %v", err)
|
||||
config.Log.Fatalf("Redis no disponible: %v", err)
|
||||
}
|
||||
config.Log.Info("✅ Redis conectado")
|
||||
config.Log.Info("Redis conectado")
|
||||
|
||||
// Crear proveedor de configuración desde Redis
|
||||
redisManager := config.NewRedisManager(redisClient)
|
||||
@ -43,14 +47,14 @@ func main() {
|
||||
// Conexión a Base de Datos
|
||||
database := config.GetDatabaseConnection(conf)
|
||||
if database == nil {
|
||||
config.Log.Fatal("❌ No se pudo establecer la conexión con la base de datos.")
|
||||
config.Log.Fatal("No se pudo establecer la conexión con la base de datos.")
|
||||
}
|
||||
config.Log.Info("✅ Conexión a base de datos establecida")
|
||||
config.Log.Info("Conexión a base de datos establecida")
|
||||
|
||||
scheduler.Start(context.Background(), redisClient, redisConfigProvider, database, *emailService)
|
||||
config.Log.Info("✅ Scheduler en ejecución y escuchando recargas")
|
||||
config.Log.Info("Scheduler en ejecución y escuchando recargas")
|
||||
|
||||
//metrics Grafana
|
||||
// Metrics Grafana/Prometheus
|
||||
metrics.Register()
|
||||
startMetricsServer()
|
||||
|
||||
@ -59,13 +63,24 @@ func main() {
|
||||
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
|
||||
<-stop
|
||||
|
||||
config.Log.Info("🛑 Señal de apagado recibida, cerrando servicio...")
|
||||
config.Log.Info("Señal de apagado recibida, cerrando servicio...")
|
||||
}
|
||||
|
||||
func initTimezone() {
|
||||
loc, err := time.LoadLocation("America/La_Paz")
|
||||
if err != nil {
|
||||
// Si falla la carga, mantenemos la zona por defecto del entorno
|
||||
// y solo registramos el problema en stdout para no depender del logger aún.
|
||||
fmt.Println("No se pudo cargar la zona horaria America/La_Paz:", err)
|
||||
return
|
||||
}
|
||||
time.Local = loc
|
||||
}
|
||||
|
||||
func startMetricsServer() {
|
||||
go func() {
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
config.Log.Info("📊 Servidor de métricas en :9100/metrics")
|
||||
http.ListenAndServe(":9100", nil)
|
||||
config.Log.Info("Servidor de métricas en :9100/metrics")
|
||||
_ = http.ListenAndServe(":9100", nil)
|
||||
}()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user