alive 0.1.4

use mysql to check is service alive
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use aok::Result;
use mysql_macro::q01;

pub async fn err_duration(watch_id: u64) -> Result<String> {
  if let Some::<(u8, u64)>((state, ts)) = q01!(format!(
    "SELECT state,ts FROM log WHERE watch_id={watch_id} ORDER BY id DESC LIMIT 1"
  )) {
    if state == 1 {
      let now = sts::sec();
      if now > ts {
        let n = (now - ts) / 60;
        return Ok(format!("{n} 分钟"));
      }
    }
  }
  Ok("".to_owned())
}