about summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 61969bcff92a..9f4eea03fa31 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -42,6 +42,8 @@ extern crate rand;
 extern crate reqwest;
 extern crate serde;
 extern crate serde_json;
+extern crate tokio;
+extern crate tokio_timer;
 extern crate url;
 extern crate url_serde;
 
@@ -86,6 +88,8 @@ fn main() {
 
     let db_addr = SyncArbiter::start(2, move || DbExecutor(pool.clone()));
 
+    schedule_search_refresh(db_addr.clone());
+
     info!("Initialising OIDC integration ...");
     let oidc_url = config("OIDC_DISCOVERY_URL");
     let oidc_config = oidc::load_oidc(&oidc_url)
@@ -162,3 +166,18 @@ fn main() {
 
     let _ = sys.run();
 }
+
+fn schedule_search_refresh(db: Addr<Syn, DbExecutor>) {
+    use tokio::prelude::*;
+    use tokio::timer::Interval;
+    use std::time::{Duration, Instant};
+    use std::thread;
+
+    let task = Interval::new(Instant::now(), Duration::from_secs(60))
+        .from_err()
+        .for_each(move |_| db.send(db::RefreshSearchView).flatten())
+        .map_err(|err| error!("Error while updating search view: {}", err));
+        //.and_then(|_| debug!("Refreshed search view in DB"));
+
+    thread::spawn(|| tokio::run(task));
+}