chore: refresh all server's info on purpose, get the actual health info (#225)

* chore: refresh all server's info

* chore: update release notes
This commit is contained in:
Medcl
2025-02-28 11:48:25 +08:00
committed by GitHub
parent de46300ee4
commit 9fd56457d8
2 changed files with 28 additions and 0 deletions

View File

@@ -30,6 +30,8 @@ Information about release notes of Coco Server is provided here.
- Refactoring assistant api #195 - Refactoring assistant api #195
- Refactor: remove websocket_session_id from message request #206 - Refactor: remove websocket_session_id from message request #206
- Refactor: the display of search results and the logic of creating new chats #207 - Refactor: the display of search results and the logic of creating new chats #207
- Refresh all server's info on purpose, get the actual health info #225
## 0.1.0 (2015-02-16) ## 0.1.0 (2015-02-16)

View File

@@ -259,6 +259,10 @@ pub async fn load_or_insert_default_server<R: Runtime>(
pub async fn list_coco_servers<R: Runtime>( pub async fn list_coco_servers<R: Runtime>(
_app_handle: AppHandle<R>, _app_handle: AppHandle<R>,
) -> Result<Vec<Server>, String> { ) -> Result<Vec<Server>, String> {
//hard fresh all server's info, in order to get the actual health
refresh_all_coco_server_info(_app_handle.clone()).await;
let servers: Vec<Server> = get_all_servers(); let servers: Vec<Server> = get_all_servers();
Ok(servers) Ok(servers)
} }
@@ -278,6 +282,15 @@ pub const COCO_SERVERS: &str = "coco_servers";
const COCO_SERVER_TOKENS: &str = "coco_server_tokens"; const COCO_SERVER_TOKENS: &str = "coco_server_tokens";
pub async fn refresh_all_coco_server_info<R: Runtime>(
app_handle: AppHandle<R>,
) {
let servers = get_all_servers();
for server in servers {
let _ = refresh_coco_server_info(app_handle.clone(), server.id.clone()).await;
}
}
#[tauri::command] #[tauri::command]
pub async fn refresh_coco_server_info<R: Runtime>( pub async fn refresh_coco_server_info<R: Runtime>(
app_handle: AppHandle<R>, app_handle: AppHandle<R>,
@@ -328,9 +341,11 @@ pub async fn refresh_coco_server_info<R: Runtime>(
Err("Received empty response body.".to_string()) Err("Received empty response body.".to_string())
} }
} else { } else {
mark_server_as_offline(id.as_str()).await;
Err("Could not determine the content length.".to_string()) Err("Could not determine the content length.".to_string())
} }
} else { } else {
mark_server_as_offline(id.as_str()).await;
Err(format!("Request failed with status: {}", response.status())) Err(format!("Request failed with status: {}", response.status()))
} }
} else { } else {
@@ -453,6 +468,17 @@ pub async fn enable_server<R: Runtime>(app_handle: AppHandle<R>, id: String) ->
Ok(()) Ok(())
} }
pub async fn mark_server_as_offline(id: &str) {
// println!("server_is_offline: {}", id);
let server = get_server_by_id(id);
if let Some(mut server) = server {
server.available = false;
server.health = None;
save_server(&server);
}
}
#[tauri::command] #[tauri::command]
pub async fn disable_server<R: Runtime>(app_handle: AppHandle<R>, id: String) -> Result<(), ()> { pub async fn disable_server<R: Runtime>(app_handle: AppHandle<R>, id: String) -> Result<(), ()> {
println!("disable_server: {}", id); println!("disable_server: {}", id);