Skip to content

Commit

Permalink
Timeout the ping redis method so the health route can return without …
Browse files Browse the repository at this point in the history
…fully timing out
  • Loading branch information
spencewenski committed May 5, 2024
1 parent fd1acbf commit c665fb8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/controller/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use serde_derive::{Deserialize, Serialize};
use serde_with::{serde_as, skip_serializing_none};
#[cfg(feature = "sidekiq")]
use sidekiq::redis_rs::cmd;
#[cfg(feature = "sidekiq")]
use tokio::time::timeout;
use tracing::instrument;

use crate::app_context::AppContext;
Expand Down Expand Up @@ -172,7 +174,7 @@ async fn redis_health(redis: &sidekiq::RedisPool) -> ResourceHealth {
#[instrument(skip_all)]
async fn ping_redis(redis: &sidekiq::RedisPool) -> anyhow::Result<(Duration, Duration)> {
let timer = Instant::now();
let mut conn = redis.get().await?;
let mut conn = timeout(Duration::from_secs(5), redis.get()).await??;
let acquire_conn_latency = timer.elapsed();

let timer = Instant::now();
Expand Down

0 comments on commit c665fb8

Please sign in to comment.