changeset 9:b8b99af28199

Notify of new data
author Lewin Bormann <lbo@spheniscida.de>
date Tue, 01 Dec 2020 21:39:06 +0100
parents a5de18a5e99e
children 625c0c52e631
files Cargo.toml src/main.rs
diffstat 2 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Cargo.toml	Tue Dec 01 21:22:08 2020 +0100
+++ b/Cargo.toml	Tue Dec 01 21:39:06 2020 +0100
@@ -17,3 +17,4 @@
 version = "~0.4"
 default-features = false
 features = ["postgres_pool"]
+
--- a/src/main.rs	Tue Dec 01 21:22:08 2020 +0100
+++ b/src/main.rs	Tue Dec 01 21:39:06 2020 +0100
@@ -108,8 +108,6 @@
         .and_then(flexible_timestamp_parse)
         .unwrap_or(chrono::Utc::now());
     let max = max.unwrap_or(16384);
-    //println!("from {:?} to {:?}", from_ts, to_ts);
-    //println!("secret {:?}", secret);
 
     let stmt = db.0.prepare_cached(
         r"SELECT t, lat, long, spd, ele FROM geohub.geodata
@@ -119,7 +117,6 @@
         .query(&[&name, &from_ts, &to_ts, &secret, &max])
         .unwrap();
     {
-        println!("got {} rows", rows.len());
         returnable.features = Vec::with_capacity(rows.len());
         for row in rows.iter() {
             let (ts, lat, long, spd, ele): (
@@ -161,8 +158,12 @@
         ts = flexible_timestamp_parse(time).unwrap_or(ts);
     }
     let stmt = db.0.prepare_cached("INSERT INTO geohub.geodata (id, lat, long, spd, t, ele, secret) VALUES ($1, $2, $3, $4, $5, $6, public.digest($7, 'sha256'))").unwrap();
+    let notify =
+        db.0.prepare_cached(format!("NOTIFY {}, '{}'", name, name).as_str())
+            .unwrap();
     stmt.execute(&[&name, &lat, &longitude, &s, &ts, &ele, &secret])
         .unwrap();
+    notify.execute(&[]).unwrap();
     rocket::http::Status::Ok
 }