From 6f94a825485b1d622d8ebe88ddf3e2f426d1c69c Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 29 Nov 2023 15:48:26 +0100 Subject: update to axum 0.7 and cargo update --- src/services/ping.rs | 66 ++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 36 deletions(-) (limited to 'src/services') diff --git a/src/services/ping.rs b/src/services/ping.rs index c3bdced..0f773f4 100644 --- a/src/services/ping.rs +++ b/src/services/ping.rs @@ -85,17 +85,14 @@ pub async fn status_websocket(mut socket: WebSocket, state: Arc) { trace!("Search for uuid: {}", uuid); let eta = get_eta(&state.db).await; - let _ = socket.send(Message::Text(format!("eta_{}_{}", eta, uuid))).await; + let _ = socket.send(Message::Text(format!("eta_{eta}_{uuid}"))).await; let device_exists = state.ping_map.contains_key(&uuid); - match device_exists { - true => { - let _ = socket.send(process_device(state.clone(), uuid).await).await; - }, - false => { - debug!("didn't find any device"); - let _ = socket.send(Message::Text(format!("notfound_{}", uuid))).await; - }, + if device_exists { + let _ = socket.send(process_device(state.clone(), uuid).await).await; + } else { + debug!("didn't find any device"); + let _ = socket.send(Message::Text(format!("notfound_{uuid}"))).await; }; let _ = socket.close().await; @@ -118,34 +115,31 @@ async fn process_device(state: Arc, uuid: String) -> Message { let pm = state.ping_map.clone().into_read_only(); let device = pm.get(&uuid).expect("fatal error"); debug!("got device: {} (online: {})", device.ip, device.online); - match device.online { - true => { - debug!("already started"); - Message::Text(format!("start_{}", uuid)) - }, - false => { - loop{ - trace!("wait for tx message"); - let message = state.ping_send.subscribe().recv().await.expect("fatal error"); - trace!("got message {:?}", message); - return match message { - BroadcastCommands::Success(msg_uuid) => { - if msg_uuid != uuid { continue; } - trace!("message == uuid success"); - Message::Text(format!("start_{}", uuid)) - }, - BroadcastCommands::Timeout(msg_uuid) => { - if msg_uuid != uuid { continue; } - trace!("message == uuid timeout"); - Message::Text(format!("timeout_{}", uuid)) - }, - BroadcastCommands::Error(msg_uuid) => { - if msg_uuid != uuid { continue; } - trace!("message == uuid error"); - Message::Text(format!("error_{}", uuid)) - } + if device.online { + debug!("already started"); + Message::Text(format!("start_{uuid}")) + } else { + loop { + trace!("wait for tx message"); + let message = state.ping_send.subscribe().recv().await.expect("fatal error"); + trace!("got message {:?}", message); + return match message { + BroadcastCommands::Success(msg_uuid) => { + if msg_uuid != uuid { continue; } + trace!("message == uuid success"); + Message::Text(format!("start_{uuid}")) + }, + BroadcastCommands::Timeout(msg_uuid) => { + if msg_uuid != uuid { continue; } + trace!("message == uuid timeout"); + Message::Text(format!("timeout_{uuid}")) + }, + BroadcastCommands::Error(msg_uuid) => { + if msg_uuid != uuid { continue; } + trace!("message == uuid error"); + Message::Text(format!("error_{uuid}")) } } } } -} \ No newline at end of file +} -- cgit v1.2.3