cabytcini/src/front.rs

31 lines
808 B
Rust
Raw Permalink Normal View History

2020-04-07 14:41:17 +00:00
use crate::{config::Config, MTState};
use log::{error, info};
use std::{thread, time};
const FIVE_MINUTES: u64 = 60 * 5;
pub fn update(st: MTState, cfg: Config) {
2020-04-07 14:41:17 +00:00
loop {
match ureq::get(&cfg.front_url)
.set("User-Agent", crate::APP_USER_AGENT)
.call()
{
2020-04-07 14:41:17 +00:00
Ok(who) => {
let mut data = st.lock().unwrap();
let who = who.into_string().unwrap().trim().to_string();
2020-04-07 14:41:17 +00:00
if who != data.front {
data.front = who;
info!("new front: {}", data.front);
}
}
Err(why) => {
error!("front error: {:?}", why);
}
}
let dur = time::Duration::new(FIVE_MINUTES, 0);
thread::sleep(dur);
}
}