28 lines
739 B
Rust
28 lines
739 B
Rust
|
use crate::{config::Config, MTState};
|
||
|
use log::{error, info};
|
||
|
use std::{thread, time};
|
||
|
|
||
|
const FIVE_MINUTES: u64 = 60 * 5;
|
||
|
|
||
|
pub(crate) fn update(st: MTState, cfg: Config) {
|
||
|
loop {
|
||
|
match reqwest::blocking::get(&cfg.front_url) {
|
||
|
Ok(who) => {
|
||
|
let mut data = st.lock().unwrap();
|
||
|
let who = who.text().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);
|
||
|
}
|
||
|
}
|