configurable cleanup interval
This commit is contained in:
parent
04a0faa604
commit
111e830410
|
@ -42,6 +42,7 @@ pub struct Configuration {
|
||||||
http: Option<HTTPConfig>,
|
http: Option<HTTPConfig>,
|
||||||
log_level: Option<String>,
|
log_level: Option<String>,
|
||||||
db_path: Option<String>,
|
db_path: Option<String>,
|
||||||
|
cleanup_interval: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -94,6 +95,10 @@ impl Configuration {
|
||||||
pub fn get_db_path(&self) -> &Option<String> {
|
pub fn get_db_path(&self) -> &Option<String> {
|
||||||
&self.db_path
|
&self.db_path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_cleanup_interval(&self) -> &Option<u64> {
|
||||||
|
&self.cleanup_interval
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Configuration {
|
impl Default for Configuration {
|
||||||
|
@ -107,6 +112,7 @@ impl Default for Configuration {
|
||||||
},
|
},
|
||||||
http: None,
|
http: None,
|
||||||
db_path: None,
|
db_path: None,
|
||||||
|
cleanup_interval: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,10 +149,14 @@ fn main() {
|
||||||
Some(db_path) => {
|
Some(db_path) => {
|
||||||
let db_p = db_path.clone();
|
let db_p = db_path.clone();
|
||||||
let tracker_clone = tracker.clone();
|
let tracker_clone = tracker.clone();
|
||||||
|
let cleanup_interval = match *cfg.get_cleanup_interval() {
|
||||||
|
Some(v) => v,
|
||||||
|
None => 10 * 60,
|
||||||
|
};
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
loop {
|
loop {
|
||||||
std::thread::sleep(std::time::Duration::new(120, 0));
|
std::thread::sleep(std::time::Duration::new(cleanup_interval, 0));
|
||||||
debug!("periodically saving database.");
|
debug!("periodically saving database.");
|
||||||
tracker_clone.periodic_task(db_p.as_str());
|
tracker_clone.periodic_task(db_p.as_str());
|
||||||
debug!("database saved.");
|
debug!("database saved.");
|
||||||
|
|
Loading…
Reference in a new issue