Skip to content

Commit

Permalink
Skip healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Janaka-Steph committed Nov 3, 2023
1 parent a29c188 commit c48f061
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
62 changes: 37 additions & 25 deletions src-tauri/src/controller_binaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,31 +135,43 @@ pub async fn start_service(
.spawn()
.map_err(|e| format!("Failed to spawn child process: {}", e))?;

// Check if the service is running calling /v1 endpoint every 500ms
let interval_duration = Duration::from_millis(500);
let mut interval = interval(interval_duration);
loop {
interval.tick().await;
let base_url = get_base_url(&services_guard[&service_id])?;
let url = format!("{}/v1", base_url);
let client = reqwest::Client::new();
let res = client.get(&url).send().await;
match res {
Ok(response) => {
// If /v1 is not implemented by the service, it will return 400 Bad Request, consider it as success
if response.status().is_success()
|| response.status() == reqwest::StatusCode::BAD_REQUEST
{
let mut running_services_guard = state.running_services.lock().await;
running_services_guard.insert(service_id.clone(), child);
log::info!("Service started: {}", service_id);
break;
} else {
log::error!("Service failed to start: {}", service_id);
let skip_service_check = services_guard
.get(&service_id)
.map(|service| service.skip_health_check)
.unwrap_or(Some(false))
.unwrap();

if skip_service_check {
let mut running_services_guard = state.running_services.lock().await;
running_services_guard.insert(service_id.clone(), child);
log::info!("Service started: {}", service_id);
} else {
// Check if the service is running calling /v1 endpoint every 500ms
let interval_duration = Duration::from_millis(500);
let mut interval = interval(interval_duration);
loop {
interval.tick().await;
let base_url = get_base_url(&services_guard[&service_id])?;
let url = format!("{}/v1", base_url);
let client = reqwest::Client::new();
let res = client.get(&url).send().await;
match res {
Ok(response) => {
// If /v1 is not implemented by the service, it will return 400 Bad Request, consider it as success
if response.status().is_success()
|| response.status() == reqwest::StatusCode::BAD_REQUEST
{
let mut running_services_guard = state.running_services.lock().await;
running_services_guard.insert(service_id.clone(), child);
log::info!("Service started: {}", service_id);
break;
} else {
log::error!("Service failed to start: {}", service_id);
}
}
Err(e) => {
log::error!("Failed to send request: {}", e);
}
}
Err(e) => {
log::error!("Failed to send request: {}", e);
}
}
}
Expand Down Expand Up @@ -451,7 +463,7 @@ pub async fn get_system_stats() -> Result<HashMap<String, String>> {
}

#[tauri::command(async)]
pub async fn get_service_stats(service_id: String) -> Result<HashMap<String, String>> {
pub async fn get_service_stats(_service_id: String) -> Result<HashMap<String, String>> {
Ok(HashMap::new())
}
#[tauri::command(async)]
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct Service {
running_port: Option<u32>,
#[serde(rename = "serviceType")]
service_type: Option<String>,
#[serde(rename = "skipHealthCheck")]
skip_health_check: Option<bool>,
version: Option<String>,
#[serde(rename = "weightsDirectoryUrl")]
weights_directory_url: Option<String>,
Expand Down

0 comments on commit c48f061

Please sign in to comment.