Skip to content

Commit

Permalink
fix(ping): correct status check
Browse files Browse the repository at this point in the history
  • Loading branch information
Veirt committed Aug 30, 2024
1 parent 7f507fc commit f312c16
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ use std::sync::Arc;

use axum::{extract::Query, response::IntoResponse, Extension, Json};
use maud::{html, Markup};
use reqwest::{Client, StatusCode};
use reqwest::{Client, Error, StatusCode};
use serde::Deserialize;
use serde_json::json;

use crate::AppState;
use crate::{config::PingConfig, AppState};

#[derive(Deserialize)]
pub struct QueryParams {
group: String,
title: String,
}

async fn is_service_up(client: &reqwest::Client, ping_config: &PingConfig) -> Result<bool, Error> {
let response = client.get(&ping_config.url).send().await?;
Ok(response.status().is_success())
}

pub async fn ping_handler(
Extension(state): Extension<Arc<AppState>>,
Query(params): Query<QueryParams>,
Expand Down Expand Up @@ -47,7 +53,7 @@ pub async fn ping_handler(
)
})?;

let is_service_up = client.get(&ping_config.url).send().await.is_ok();
let is_service_up = is_service_up(&client, ping_config).await.unwrap_or(false);

if is_service_up {
Ok(html!(
Expand Down

0 comments on commit f312c16

Please sign in to comment.