diff options
Diffstat (limited to 'src/services')
-rw-r--r-- | src/services/ping.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/services/ping.rs b/src/services/ping.rs index 0f773f4..7d71218 100644 --- a/src/services/ping.rs +++ b/src/services/ping.rs | |||
@@ -2,26 +2,26 @@ use std::str::FromStr; | |||
2 | use std::net::IpAddr; | 2 | use std::net::IpAddr; |
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use axum::extract::{ws::WebSocket}; | 5 | use axum::extract::ws::WebSocket; |
6 | use axum::extract::ws::Message; | 6 | use axum::extract::ws::Message; |
7 | use dashmap::DashMap; | 7 | use dashmap::DashMap; |
8 | use sqlx::PgPool; | 8 | use sqlx::PgPool; |
9 | use time::{Duration, Instant}; | 9 | use time::{Duration, Instant}; |
10 | use tokio::sync::broadcast::{Sender}; | 10 | use tokio::sync::broadcast::Sender; |
11 | use tracing::{debug, error, trace}; | 11 | use tracing::{debug, error, trace}; |
12 | use crate::AppState; | 12 | use crate::AppState; |
13 | use crate::config::SETTINGS; | 13 | use crate::config::SETTINGS; |
14 | use crate::db::Device; | 14 | use crate::db::Device; |
15 | 15 | ||
16 | pub type PingMap = DashMap<String, PingValue>; | 16 | pub type StatusMap = DashMap<String, Value>; |
17 | 17 | ||
18 | #[derive(Debug, Clone)] | 18 | #[derive(Debug, Clone)] |
19 | pub struct PingValue { | 19 | pub struct Value { |
20 | pub ip: String, | 20 | pub ip: String, |
21 | pub online: bool | 21 | pub online: bool |
22 | } | 22 | } |
23 | 23 | ||
24 | pub async fn spawn(tx: Sender<BroadcastCommands>, device: Device, uuid: String, ping_map: &PingMap, db: &PgPool) { | 24 | pub async fn spawn(tx: Sender<BroadcastCommands>, device: Device, uuid: String, ping_map: &StatusMap, db: &PgPool) { |
25 | let timer = Instant::now(); | 25 | let timer = Instant::now(); |
26 | let payload = [0; 8]; | 26 | let payload = [0; 8]; |
27 | 27 | ||
@@ -63,7 +63,7 @@ pub async fn spawn(tx: Sender<BroadcastCommands>, device: Device, uuid: String, | |||
63 | timer.elapsed().whole_seconds(), | 63 | timer.elapsed().whole_seconds(), |
64 | device.id | 64 | device.id |
65 | ).execute(db).await.unwrap(); | 65 | ).execute(db).await.unwrap(); |
66 | ping_map.insert(uuid.clone(), PingValue { ip: device.ip.clone(), online: true }); | 66 | ping_map.insert(uuid.clone(), Value { ip: device.ip.clone(), online: true }); |
67 | tokio::time::sleep(tokio::time::Duration::from_secs(60)).await; | 67 | tokio::time::sleep(tokio::time::Duration::from_secs(60)).await; |
68 | } | 68 | } |
69 | trace!("remove {} from ping_map", uuid); | 69 | trace!("remove {} from ping_map", uuid); |
@@ -107,7 +107,7 @@ async fn get_eta(db: &PgPool) -> i64 { | |||
107 | None => { vec![0] }, | 107 | None => { vec![0] }, |
108 | Some(t) => t, | 108 | Some(t) => t, |
109 | }; | 109 | }; |
110 | times.iter().sum::<i64>() / times.len() as i64 | 110 | times.iter().sum::<i64>() / i64::try_from(times.len()).unwrap() |
111 | 111 | ||
112 | } | 112 | } |
113 | 113 | ||