summaryrefslogtreecommitdiff
path: root/src/services/ping.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/ping.rs')
-rw-r--r--src/services/ping.rs66
1 files changed, 30 insertions, 36 deletions
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<AppState>) {
85 trace!("Search for uuid: {}", uuid); 85 trace!("Search for uuid: {}", uuid);
86 86
87 let eta = get_eta(&state.db).await; 87 let eta = get_eta(&state.db).await;
88 let _ = socket.send(Message::Text(format!("eta_{}_{}", eta, uuid))).await; 88 let _ = socket.send(Message::Text(format!("eta_{eta}_{uuid}"))).await;
89 89
90 let device_exists = state.ping_map.contains_key(&uuid); 90 let device_exists = state.ping_map.contains_key(&uuid);
91 match device_exists { 91 if device_exists {
92 true => { 92 let _ = socket.send(process_device(state.clone(), uuid).await).await;
93 let _ = socket.send(process_device(state.clone(), uuid).await).await; 93 } else {
94 }, 94 debug!("didn't find any device");
95 false => { 95 let _ = socket.send(Message::Text(format!("notfound_{uuid}"))).await;
96 debug!("didn't find any device");
97 let _ = socket.send(Message::Text(format!("notfound_{}", uuid))).await;
98 },
99 }; 96 };
100 97
101 let _ = socket.close().await; 98 let _ = socket.close().await;
@@ -118,34 +115,31 @@ async fn process_device(state: Arc<AppState>, uuid: String) -> Message {
118 let pm = state.ping_map.clone().into_read_only(); 115 let pm = state.ping_map.clone().into_read_only();
119 let device = pm.get(&uuid).expect("fatal error"); 116 let device = pm.get(&uuid).expect("fatal error");
120 debug!("got device: {} (online: {})", device.ip, device.online); 117 debug!("got device: {} (online: {})", device.ip, device.online);
121 match device.online { 118 if device.online {
122 true => { 119 debug!("already started");
123 debug!("already started"); 120 Message::Text(format!("start_{uuid}"))
124 Message::Text(format!("start_{}", uuid)) 121 } else {
125 }, 122 loop {
126 false => { 123 trace!("wait for tx message");
127 loop{ 124 let message = state.ping_send.subscribe().recv().await.expect("fatal error");
128 trace!("wait for tx message"); 125 trace!("got message {:?}", message);
129 let message = state.ping_send.subscribe().recv().await.expect("fatal error"); 126 return match message {
130 trace!("got message {:?}", message); 127 BroadcastCommands::Success(msg_uuid) => {
131 return match message { 128 if msg_uuid != uuid { continue; }
132 BroadcastCommands::Success(msg_uuid) => { 129 trace!("message == uuid success");
133 if msg_uuid != uuid { continue; } 130 Message::Text(format!("start_{uuid}"))
134 trace!("message == uuid success"); 131 },
135 Message::Text(format!("start_{}", uuid)) 132 BroadcastCommands::Timeout(msg_uuid) => {
136 }, 133 if msg_uuid != uuid { continue; }
137 BroadcastCommands::Timeout(msg_uuid) => { 134 trace!("message == uuid timeout");
138 if msg_uuid != uuid { continue; } 135 Message::Text(format!("timeout_{uuid}"))
139 trace!("message == uuid timeout"); 136 },
140 Message::Text(format!("timeout_{}", uuid)) 137 BroadcastCommands::Error(msg_uuid) => {
141 }, 138 if msg_uuid != uuid { continue; }
142 BroadcastCommands::Error(msg_uuid) => { 139 trace!("message == uuid error");
143 if msg_uuid != uuid { continue; } 140 Message::Text(format!("error_{uuid}"))
144 trace!("message == uuid error");
145 Message::Text(format!("error_{}", uuid))
146 }
147 } 141 }
148 } 142 }
149 } 143 }
150 } 144 }
151} \ No newline at end of file 145}