Skip to content
Snippets Groups Projects

Resolve "Implement DB Integration"

Merged Phil Höfer requested to merge 35-implement-db-integration into main
1 file
+ 7
0
Compare changes
  • Side-by-side
  • Inline
+ 7
0
@@ -26,6 +26,7 @@ use postgres::{Client, NoTls};
fn main() -> Result<(), io::Error> {
let mut last_update = std::time::SystemTime::now();
let config_toml = read_config("data/config.toml").or(read_config("config.toml")).unwrap().parse::<Table>().unwrap();
let mut config = HashMap::new();
for (key, value) in config_toml {
@@ -101,6 +102,12 @@ fn main() -> Result<(), io::Error> {
//println!("Query: {}, Prediction:{}", query, prediction);
let response = Response::from_string(prediction);
request.respond(response);
let now = std::time::SystemTime::now();
let elapsed = now.duration_since(last_update).expect("Time went backwards");
if elapsed >= std::time::Duration::from_secs(24 * 60 * 60) {
markov_chain = read_from_db(config.clone(), markov_chain);
last_update = now;
}
},
Err(e) => {
//println!("Error: {}",e);
Loading