From 0920c86de3523785b5f4ac67e2090f0736f9fcb2 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 28 Feb 2024 19:05:49 +0100 Subject: Closes #18. Added pingthreshold. Cargo update --- src/services/ping.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src/services') diff --git a/src/services/ping.rs b/src/services/ping.rs index 9191f86..8cf6072 100644 --- a/src/services/ping.rs +++ b/src/services/ping.rs @@ -49,22 +49,27 @@ pub async fn spawn( }; } + trace!(?msg); + let msg = msg.expect("fatal error"); let _ = tx.send(msg.clone()); - if let BroadcastCommands::Success = msg.command { - sqlx::query!( - r#" - UPDATE devices - SET times = array_append(times, $1) - WHERE id = $2; - "#, - timer.elapsed().whole_seconds(), - device.id - ) - .execute(db) - .await - .unwrap(); + if msg.command == BroadcastCommands::Success { + if timer.elapsed().whole_seconds() > config.pingthreshold { + sqlx::query!( + r#" + UPDATE devices + SET times = array_append(times, $1) + WHERE id = $2; + "#, + timer.elapsed().whole_seconds(), + device.id + ) + .execute(db) + .await + .unwrap(); + } + ping_map.insert( uuid.clone(), Value { -- cgit v1.2.3