cabytcini/src/front.rs

31 lines
808 B
Rust

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) {
loop {
match ureq::get(&cfg.front_url)
.set("User-Agent", crate::APP_USER_AGENT)
.call()
{
Ok(who) => {
let mut data = st.lock().unwrap();
let who = who.into_string().unwrap().trim().to_string();
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);
}
}