Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbayer committed Nov 26, 2024
1 parent e49dae0 commit 43eca3f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
13 changes: 4 additions & 9 deletions relay-server/src/endpoints/health_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@ struct Status {
is_healthy: bool,
}

const UNHEALTHY: (hyper::StatusCode, axum::Json<Status>) = (
StatusCode::SERVICE_UNAVAILABLE,
axum::Json(Status { is_healthy: false }),
);

pub async fn handle(state: ServiceState, Path(kind): Path<IsHealthy>) -> impl IntoResponse {
if state.has_crashed() {
return UNHEALTHY;
}
match state.health_check().send(kind).await {
Ok(HealthStatus::Healthy) => (StatusCode::OK, axum::Json(Status { is_healthy: true })),
_ => UNHEALTHY,
_ => (
StatusCode::SERVICE_UNAVAILABLE,
axum::Json(Status { is_healthy: false }),
),
}
}

Expand Down
19 changes: 0 additions & 19 deletions relay-server/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::convert::Infallible;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use std::time::Duration;

Expand Down Expand Up @@ -136,7 +135,6 @@ struct StateInner {
config: Arc<Config>,
memory_checker: MemoryChecker,
registry: Registry,
service_crashed: AtomicBool,
}

/// Server state.
Expand Down Expand Up @@ -335,7 +333,6 @@ impl ServiceState {
config: config.clone(),
memory_checker: MemoryChecker::new(memory_stat, config.clone()),
registry,
service_crashed: false.into(),
};

Ok((
Expand Down Expand Up @@ -412,22 +409,6 @@ impl ServiceState {
pub fn outcome_aggregator(&self) -> &Addr<TrackOutcome> {
&self.inner.registry.outcome_aggregator
}

/// Checks whether one of the services has crashed.
pub fn has_crashed(&self) -> bool {
self.inner
.service_crashed
.load(std::sync::atomic::Ordering::Relaxed)
}

/// Reports that one of the services has crashed.
///
/// Marks the entire service state as unhealthy.
pub fn report_crash(&self) {
self.inner
.service_crashed
.store(true, std::sync::atomic::Ordering::Relaxed);
}
}

fn create_redis_pool(redis_config: RedisConfigRef) -> Result<RedisPool, RedisError> {
Expand Down

0 comments on commit 43eca3f

Please sign in to comment.