Skip to content

Commit

Permalink
Less redis error messages during standalone initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
zakstucke committed Jul 23, 2024
1 parent 58cf535 commit 744cf58
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .zetch.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rust/bitbazaar/redis/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use deadpool_redis::redis::{FromRedisValue, ToRedisArgs};
use once_cell::sync::Lazy;

use super::batch::{RedisBatch, RedisBatchFire, RedisBatchReturningOps};
use crate::{errors::prelude::*, redis::RedisScript};
use crate::{errors::prelude::*, log::record_exception, redis::RedisScript};

/// Wrapper around a lazy redis connection.
pub struct RedisConn<'a> {
Expand Down Expand Up @@ -33,7 +33,7 @@ impl<'a> RedisConn<'a> {
match self.pool.get().await {
Ok(conn) => self.conn = Some(conn),
Err(e) => {
tracing::error!("Could not get redis connection: {}", e);
record_exception("Failed to get redis connection.", format!("{:?}", e));
return None;
}
}
Expand Down
18 changes: 10 additions & 8 deletions rust/bitbazaar/redis/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ impl RedisStandalone {
let child = cmd.spawn().change_context(AnyErr)?;

// Wait for redis to come up, raising if waited for 10 seconds.
let client = Redis::new(
format!("redis://localhost:{}", port),
uuid::Uuid::new_v4().to_string(),
)?;
let mut up = false;
let elapsed = Instant::now();
while !up && elapsed.elapsed() < std::time::Duration::from_secs(10) {
up = Redis::new(
format!("redis://localhost:{}", port),
uuid::Uuid::new_v4().to_string(),
)?
.conn()
.ping()
.await
// Using low level check of conn first, as inner will record an exception which we don't really need during this startup check:
if client.get_inner_pool().get().await.is_ok() {
up = client.conn().ping().await
}
}
if up {
// Final ping as that interface conn() will actually log an error on failure to connect:
if up || client.conn().ping().await {
Ok(Self { child, port })
} else {
Err(anyerr!("RedisStandalone process not ready in 10 seconds."))
Expand Down

0 comments on commit 744cf58

Please sign in to comment.