configurable cleanup interval

This commit is contained in:
Naim A 2018-12-11 03:03:14 +02:00
parent 04a0faa604
commit 111e830410
No known key found for this signature in database
GPG key ID: FD7948915D9EF8B9
2 changed files with 11 additions and 1 deletions

View file

@ -42,6 +42,7 @@ pub struct Configuration {
http: Option<HTTPConfig>,
log_level: Option<String>,
db_path: Option<String>,
cleanup_interval: Option<u64>,
}
#[derive(Debug)]
@ -94,6 +95,10 @@ impl Configuration {
pub fn get_db_path(&self) -> &Option<String> {
&self.db_path
}
pub fn get_cleanup_interval(&self) -> &Option<u64> {
&self.cleanup_interval
}
}
impl Default for Configuration {
@ -107,6 +112,7 @@ impl Default for Configuration {
},
http: None,
db_path: None,
cleanup_interval: None,
}
}
}

View file

@ -149,10 +149,14 @@ fn main() {
Some(db_path) => {
let db_p = db_path.clone();
let tracker_clone = tracker.clone();
let cleanup_interval = match *cfg.get_cleanup_interval() {
Some(v) => v,
None => 10 * 60,
};
std::thread::spawn(move || {
loop {
std::thread::sleep(std::time::Duration::new(120, 0));
std::thread::sleep(std::time::Duration::new(cleanup_interval, 0));
debug!("periodically saving database.");
tracker_clone.periodic_task(db_p.as_str());
debug!("database saved.");