@@ -43,7 +43,11 @@ func OpenClickHouse(cfg ClickHouseConfig) (*sql.DB, error) {
|
||||
}
|
||||
|
||||
// OpenClickHouseWithRetry attempts to connect to ClickHouse with retries and backoff.
|
||||
func OpenClickHouseWithRetry(cfg ClickHouseConfig, maxRetries int, initialDelay time.Duration) (*sql.DB, error) {
|
||||
func OpenClickHouseWithRetry(
|
||||
cfg ClickHouseConfig,
|
||||
maxRetries int,
|
||||
initialDelay time.Duration,
|
||||
) (*sql.DB, error) {
|
||||
var lastErr error
|
||||
delay := initialDelay
|
||||
|
||||
@@ -53,10 +57,20 @@ func OpenClickHouseWithRetry(cfg ClickHouseConfig, maxRetries int, initialDelay
|
||||
return db, nil
|
||||
}
|
||||
lastErr = err
|
||||
log.Printf("ClickHouse connection attempt %d/%d failed: %v, retrying in %v...", i+1, maxRetries, err, delay)
|
||||
log.Printf(
|
||||
"ClickHouse connection attempt %d/%d failed: %v, retrying in %v...",
|
||||
i+1,
|
||||
maxRetries,
|
||||
err,
|
||||
delay,
|
||||
)
|
||||
time.Sleep(delay)
|
||||
delay *= 2
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("clickhouse connection failed after %d attempts: %w", maxRetries, lastErr)
|
||||
return nil, fmt.Errorf(
|
||||
"clickhouse connection failed after %d attempts: %w",
|
||||
maxRetries,
|
||||
lastErr,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user