added back off and log fatal

This commit is contained in:
2026-05-21 08:03:10 +08:00
parent d13f9bced8
commit a6666ff7da
+7 -1
View File
@@ -212,13 +212,19 @@ func main() {
helper.LogInfo("INFO: Initializing database connection...") helper.LogInfo("INFO: Initializing database connection...")
var database *sql.DB var database *sql.DB
attempts := 0
backoffTimes := []time.Duration{2 * time.Second, 5 * time.Second, 10 * time.Second}
for { for {
database, err = db.InitDB() database, err = db.InitDB()
if err == nil { if err == nil {
break break
} }
helper.LogError(fmt.Errorf("ERROR: error initializing database: %v", err), "database initialization error") helper.LogError(fmt.Errorf("ERROR: error initializing database: %v", err), "database initialization error")
time.Sleep(2 * time.Second) if attempts >= len(backoffTimes) {
log.Fatalf("FATAL: Could not initialize database after %d attempts: %v", attempts, err)
}
time.Sleep(backoffTimes[attempts])
attempts++
} }
go collectDBMetrics(database) go collectDBMetrics(database)