feat: Increase cache retry delay to 5 seconds
All checks were successful
BotServer CI / build (push) Successful in 8m25s

- Change retry interval from 1s to 5s between attempts
- Reduce attempts from 30 to 12 (still 60s total wait time)
- Gives Valkey more time to stabilize between connection attempts
- Helps with slow-to-start services during bootstrap

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Rodrigo Rodriguez 2026-02-15 00:37:59 +00:00
parent 8d0fd9da3d
commit 278b92d5fa

View file

@ -283,7 +283,7 @@ pub async fn init_redis() -> Option<Arc<redis::Client>> {
info!("Attempting to connect to cache at: {}", cache_url); info!("Attempting to connect to cache at: {}", cache_url);
let max_attempts = 30; // Try for up to 30 seconds let max_attempts = 12; // Try for up to 60 seconds (12 attempts × 5 seconds)
let mut attempt = 0; let mut attempt = 0;
loop { loop {
@ -306,8 +306,8 @@ pub async fn init_redis() -> Option<Arc<redis::Client>> {
} }
Err(e) => { Err(e) => {
if attempt < max_attempts { if attempt < max_attempts {
info!("Cache PING failed (attempt {}/{}): {}. Retrying in 1s...", attempt, max_attempts, e); info!("Cache PING failed (attempt {}/{}): {}. Retrying in 5s...", attempt, max_attempts, e);
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
continue; continue;
} else { } else {
warn!("Cache PING failed after {} attempts: {}. Cache functions will be disabled.", max_attempts, e); warn!("Cache PING failed after {} attempts: {}. Cache functions will be disabled.", max_attempts, e);
@ -319,8 +319,8 @@ pub async fn init_redis() -> Option<Arc<redis::Client>> {
} }
Err(e) => { Err(e) => {
if attempt < max_attempts { if attempt < max_attempts {
info!("Failed to establish cache connection (attempt {}/{}): {}. Retrying in 1s...", attempt, max_attempts, e); info!("Failed to establish cache connection (attempt {}/{}): {}. Retrying in 5s...", attempt, max_attempts, e);
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
continue; continue;
} else { } else {
warn!("Failed to establish cache connection after {} attempts: {}. Cache functions will be disabled.", max_attempts, e); warn!("Failed to establish cache connection after {} attempts: {}. Cache functions will be disabled.", max_attempts, e);
@ -332,8 +332,8 @@ pub async fn init_redis() -> Option<Arc<redis::Client>> {
} }
Err(e) => { Err(e) => {
if attempt < max_attempts { if attempt < max_attempts {
info!("Failed to create cache client (attempt {}/{}): {}. Retrying in 1s...", attempt, max_attempts, e); info!("Failed to create cache client (attempt {}/{}): {}. Retrying in 5s...", attempt, max_attempts, e);
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
continue; continue;
} else { } else {
log::warn!("Failed to create cache client after {} attempts: {}. Cache functions will be disabled.", max_attempts, e); log::warn!("Failed to create cache client after {} attempts: {}. Cache functions will be disabled.", max_attempts, e);