diff options
author | FxQnLr <[email protected]> | 2023-11-16 14:17:03 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2023-11-16 14:17:03 +0100 |
commit | 075b0bdc47713e303f9954556fa4b4bb472b441a (patch) | |
tree | b7ee38cc5a247151d99f0fbb75a529e5b07718e9 /src/routes | |
parent | a197f4721d3b6e79c73f16c8db69ae9f3154acec (diff) | |
download | webol-075b0bdc47713e303f9954556fa4b4bb472b441a.tar webol-075b0bdc47713e303f9954556fa4b4bb472b441a.tar.gz webol-075b0bdc47713e303f9954556fa4b4bb472b441a.zip |
check if already runs and bug fix
Diffstat (limited to 'src/routes')
-rw-r--r-- | src/routes/start.rs | 15 |
1 files changed, 13 insertions, 2 deletions
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<Arc<crate::AppState>>, headers: HeaderMap | |||
42 | )?; | 42 | )?; |
43 | let dev_id = device.id.clone(); | 43 | let dev_id = device.id.clone(); |
44 | let uuid = if payload.ping.is_some_and(|ping| ping) { | 44 | let uuid = if payload.ping.is_some_and(|ping| ping) { |
45 | let uuid_gen = Uuid::new_v4().to_string(); | 45 | let mut uuid: Option<String> = None; |
46 | for (key, value) in state.ping_map.clone() { | ||
47 | if value.ip == device.ip { | ||
48 | debug!("service already exists"); | ||
49 | uuid = Some(key); | ||
50 | break; | ||
51 | } | ||
52 | }; | ||
53 | let uuid_gen = match uuid { | ||
54 | Some(u) => u, | ||
55 | None => Uuid::new_v4().to_string(), | ||
56 | }; | ||
46 | let uuid_genc = uuid_gen.clone(); | 57 | let uuid_genc = uuid_gen.clone(); |
47 | // TODO: Check if service already runs | 58 | |
48 | tokio::spawn(async move { | 59 | tokio::spawn(async move { |
49 | debug!("init ping service"); | 60 | debug!("init ping service"); |
50 | state.ping_map.insert(uuid_gen.clone(), PingValue { ip: device.ip.clone(), online: false }); | 61 | state.ping_map.insert(uuid_gen.clone(), PingValue { ip: device.ip.clone(), online: false }); |