From 075b0bdc47713e303f9954556fa4b4bb472b441a Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Thu, 16 Nov 2023 14:17:03 +0100 Subject: check if already runs and bug fix --- src/routes/start.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/routes') diff --git a/src/routes/start.rs b/src/routes/start.rs index 401ae97..1555db3 100644 --- a/src/routes/start.rs +++ b/src/routes/start.rs @@ -42,9 +42,20 @@ pub async fn start(State(state): State>, headers: HeaderMap )?; let dev_id = device.id.clone(); let uuid = if payload.ping.is_some_and(|ping| ping) { - let uuid_gen = Uuid::new_v4().to_string(); + let mut uuid: Option = None; + for (key, value) in state.ping_map.clone() { + if value.ip == device.ip { + debug!("service already exists"); + uuid = Some(key); + break; + } + }; + let uuid_gen = match uuid { + Some(u) => u, + None => Uuid::new_v4().to_string(), + }; let uuid_genc = uuid_gen.clone(); - // TODO: Check if service already runs + tokio::spawn(async move { debug!("init ping service"); state.ping_map.insert(uuid_gen.clone(), PingValue { ip: device.ip.clone(), online: false }); -- cgit v1.2.3