summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.sqlx/query-df462bb016e2d258de146e248493f4458a532eee554d57438ef7849758238185.json15
-rw-r--r--Cargo.lock38
-rw-r--r--src/config.rs3
-rw-r--r--src/services/ping.rs31
4 files changed, 54 insertions, 33 deletions
diff --git a/.sqlx/query-df462bb016e2d258de146e248493f4458a532eee554d57438ef7849758238185.json b/.sqlx/query-df462bb016e2d258de146e248493f4458a532eee554d57438ef7849758238185.json
new file mode 100644
index 0000000..e448b24
--- /dev/null
+++ b/.sqlx/query-df462bb016e2d258de146e248493f4458a532eee554d57438ef7849758238185.json
@@ -0,0 +1,15 @@
1{
2 "db_name": "PostgreSQL",
3 "query": "\n UPDATE devices\n SET times = array_append(times, $1)\n WHERE id = $2;\n ",
4 "describe": {
5 "columns": [],
6 "parameters": {
7 "Left": [
8 "Int8",
9 "Text"
10 ]
11 },
12 "nullable": []
13 },
14 "hash": "df462bb016e2d258de146e248493f4458a532eee554d57438ef7849758238185"
15}
diff --git a/Cargo.lock b/Cargo.lock
index fcbf58a..4faf4b8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
19 19
20[[package]] 20[[package]]
21name = "ahash" 21name = "ahash"
22version = "0.8.9" 22version = "0.8.10"
23source = "registry+https://github.com/rust-lang/crates.io-index" 23source = "registry+https://github.com/rust-lang/crates.io-index"
24checksum = "d713b3834d76b85304d4d525563c1276e2e30dc97cc67bfb4585a4a29fc2c89f" 24checksum = "8b79b82693f705137f8fb9b37871d99e4f9a7df12b917eed79c3d3954830a60b"
25dependencies = [ 25dependencies = [
26 "cfg-if", 26 "cfg-if",
27 "getrandom", 27 "getrandom",
@@ -53,7 +53,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9"
53dependencies = [ 53dependencies = [
54 "proc-macro2", 54 "proc-macro2",
55 "quote", 55 "quote",
56 "syn 2.0.50", 56 "syn 2.0.51",
57] 57]
58 58
59[[package]] 59[[package]]
@@ -148,7 +148,7 @@ dependencies = [
148 "heck", 148 "heck",
149 "proc-macro2", 149 "proc-macro2",
150 "quote", 150 "quote",
151 "syn 2.0.50", 151 "syn 2.0.51",
152] 152]
153 153
154[[package]] 154[[package]]
@@ -334,9 +334,9 @@ checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
334 334
335[[package]] 335[[package]]
336name = "crossbeam-channel" 336name = "crossbeam-channel"
337version = "0.5.11" 337version = "0.5.12"
338source = "registry+https://github.com/rust-lang/crates.io-index" 338source = "registry+https://github.com/rust-lang/crates.io-index"
339checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b" 339checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95"
340dependencies = [ 340dependencies = [
341 "crossbeam-utils", 341 "crossbeam-utils",
342] 342]
@@ -1251,7 +1251,7 @@ dependencies = [
1251 "pest_meta", 1251 "pest_meta",
1252 "proc-macro2", 1252 "proc-macro2",
1253 "quote", 1253 "quote",
1254 "syn 2.0.50", 1254 "syn 2.0.51",
1255] 1255]
1256 1256
1257[[package]] 1257[[package]]
@@ -1282,7 +1282,7 @@ checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690"
1282dependencies = [ 1282dependencies = [
1283 "proc-macro2", 1283 "proc-macro2",
1284 "quote", 1284 "quote",
1285 "syn 2.0.50", 1285 "syn 2.0.51",
1286] 1286]
1287 1287
1288[[package]] 1288[[package]]
@@ -1575,7 +1575,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
1575dependencies = [ 1575dependencies = [
1576 "proc-macro2", 1576 "proc-macro2",
1577 "quote", 1577 "quote",
1578 "syn 2.0.50", 1578 "syn 2.0.51",
1579] 1579]
1580 1580
1581[[package]] 1581[[package]]
@@ -1969,9 +1969,9 @@ dependencies = [
1969 1969
1970[[package]] 1970[[package]]
1971name = "syn" 1971name = "syn"
1972version = "2.0.50" 1972version = "2.0.51"
1973source = "registry+https://github.com/rust-lang/crates.io-index" 1973source = "registry+https://github.com/rust-lang/crates.io-index"
1974checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb" 1974checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c"
1975dependencies = [ 1975dependencies = [
1976 "proc-macro2", 1976 "proc-macro2",
1977 "quote", 1977 "quote",
@@ -1986,9 +1986,9 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
1986 1986
1987[[package]] 1987[[package]]
1988name = "tempfile" 1988name = "tempfile"
1989version = "3.10.0" 1989version = "3.10.1"
1990source = "registry+https://github.com/rust-lang/crates.io-index" 1990source = "registry+https://github.com/rust-lang/crates.io-index"
1991checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" 1991checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1"
1992dependencies = [ 1992dependencies = [
1993 "cfg-if", 1993 "cfg-if",
1994 "fastrand", 1994 "fastrand",
@@ -2013,7 +2013,7 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
2013dependencies = [ 2013dependencies = [
2014 "proc-macro2", 2014 "proc-macro2",
2015 "quote", 2015 "quote",
2016 "syn 2.0.50", 2016 "syn 2.0.51",
2017] 2017]
2018 2018
2019[[package]] 2019[[package]]
@@ -2108,7 +2108,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
2108dependencies = [ 2108dependencies = [
2109 "proc-macro2", 2109 "proc-macro2",
2110 "quote", 2110 "quote",
2111 "syn 2.0.50", 2111 "syn 2.0.51",
2112] 2112]
2113 2113
2114[[package]] 2114[[package]]
@@ -2242,7 +2242,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
2242dependencies = [ 2242dependencies = [
2243 "proc-macro2", 2243 "proc-macro2",
2244 "quote", 2244 "quote",
2245 "syn 2.0.50", 2245 "syn 2.0.51",
2246] 2246]
2247 2247
2248[[package]] 2248[[package]]
@@ -2602,9 +2602,9 @@ checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6"
2602 2602
2603[[package]] 2603[[package]]
2604name = "winnow" 2604name = "winnow"
2605version = "0.6.2" 2605version = "0.6.3"
2606source = "registry+https://github.com/rust-lang/crates.io-index" 2606source = "registry+https://github.com/rust-lang/crates.io-index"
2607checksum = "7a4191c47f15cc3ec71fcb4913cb83d58def65dd3787610213c649283b5ce178" 2607checksum = "44e19b97e00a4d3db3cdb9b53c8c5f87151b5689b82cc86c2848cbdcccb2689b"
2608dependencies = [ 2608dependencies = [
2609 "memchr", 2609 "memchr",
2610] 2610]
@@ -2635,7 +2635,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
2635dependencies = [ 2635dependencies = [
2636 "proc-macro2", 2636 "proc-macro2",
2637 "quote", 2637 "quote",
2638 "syn 2.0.50", 2638 "syn 2.0.51",
2639] 2639]
2640 2640
2641[[package]] 2641[[package]]
diff --git a/src/config.rs b/src/config.rs
index 4319ffc..58043c2 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -7,6 +7,7 @@ pub struct Config {
7 pub apikey: String, 7 pub apikey: String,
8 pub serveraddr: String, 8 pub serveraddr: String,
9 pub pingtimeout: i64, 9 pub pingtimeout: i64,
10 pub pingthreshold: i64,
10} 11}
11 12
12impl Config { 13impl Config {
@@ -14,6 +15,7 @@ impl Config {
14 let config = config::Config::builder() 15 let config = config::Config::builder()
15 .set_default("serveraddr", "0.0.0.0:7229")? 16 .set_default("serveraddr", "0.0.0.0:7229")?
16 .set_default("pingtimeout", 10)? 17 .set_default("pingtimeout", 10)?
18 .set_default("pingthreshold", 1)?
17 .add_source(File::with_name("config.toml").required(false)) 19 .add_source(File::with_name("config.toml").required(false))
18 .add_source(File::with_name("config.dev.toml").required(false)) 20 .add_source(File::with_name("config.dev.toml").required(false))
19 .add_source(config::Environment::with_prefix("WEBOL").prefix_separator("_")) 21 .add_source(config::Environment::with_prefix("WEBOL").prefix_separator("_"))
@@ -22,4 +24,3 @@ impl Config {
22 config.try_deserialize() 24 config.try_deserialize()
23 } 25 }
24} 26}
25
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(
49 }; 49 };
50 } 50 }
51 51
52 trace!(?msg);
53
52 let msg = msg.expect("fatal error"); 54 let msg = msg.expect("fatal error");
53 55
54 let _ = tx.send(msg.clone()); 56 let _ = tx.send(msg.clone());
55 if let BroadcastCommands::Success = msg.command { 57 if msg.command == BroadcastCommands::Success {
56 sqlx::query!( 58 if timer.elapsed().whole_seconds() > config.pingthreshold {
57 r#" 59 sqlx::query!(
58 UPDATE devices 60 r#"
59 SET times = array_append(times, $1) 61 UPDATE devices
60 WHERE id = $2; 62 SET times = array_append(times, $1)
61 "#, 63 WHERE id = $2;
62 timer.elapsed().whole_seconds(), 64 "#,
63 device.id 65 timer.elapsed().whole_seconds(),
64 ) 66 device.id
65 .execute(db) 67 )
66 .await 68 .execute(db)
67 .unwrap(); 69 .await
70 .unwrap();
71 }
72
68 ping_map.insert( 73 ping_map.insert(
69 uuid.clone(), 74 uuid.clone(),
70 Value { 75 Value {