From e371bb15d39d6d3630652bfb4154d780b2fd5a5e Mon Sep 17 00:00:00 2001 From: F04C Date: Thu, 21 May 2026 08:03:10 +0800 Subject: [PATCH] added back off and log fatal --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index d9aff1b..f73c7d4 100644 --- a/main.go +++ b/main.go @@ -212,13 +212,19 @@ func main() { helper.LogInfo("INFO: Initializing database connection...") var database *sql.DB + attempts := 0 + backoffTimes := []time.Duration{2 * time.Second, 5 * time.Second, 10 * time.Second} for { database, err = db.InitDB() if err == nil { break } 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)