actually implement config reloading using notify

This commit is contained in:
Adrian Malacoda
2018-02-25 02:52:40 -06:00
parent 6fe20b8b86
commit c0ee8b4d6d
3 changed files with 21 additions and 4 deletions

View File

@@ -2,6 +2,9 @@ use std::env;
use std::fs::File;
use std::io::{Read, Write};
use std::sync::mpsc;
use std::time::Duration;
extern crate tenquestionmarks;
use tenquestionmarks::Tenquestionmarks;
@@ -14,6 +17,8 @@ extern crate env_logger;
extern crate time;
extern crate crossbeam;
extern crate notify;
use notify::{RecommendedWatcher, Watcher, RecursiveMode, DebouncedEvent};
fn init_logger () {
let mut builder = env_logger::Builder::new();
@@ -37,9 +42,20 @@ fn main () {
Ok(tqm) => {
info!("tenquestionmarks initialized successfully");
crossbeam::scope(|scope| {
//scope.spawn(|| {
// tqm.reconfigure(&read_config_from_file(&config_file_name));
//});
scope.spawn(|| {
let (notify_sender, notify_reciever) = mpsc::channel();
let mut watcher: RecommendedWatcher = Watcher::new(notify_sender, Duration::from_secs(2)).expect("Failed to create watcher");
watcher.watch(&config_file_name, RecursiveMode::NonRecursive).expect("Failed to watch config file");
loop {
if let Ok(event) = notify_reciever.recv() {
if let DebouncedEvent::Write(_) = event {
info!("Detected modified config file, reconfiguring");
tqm.reconfigure(&read_config_from_file(&config_file_name));
}
}
}
});
tqm.run();
})