use std::fmt::Display;
use sts::readable;
#[derive(Debug)]
pub struct Warn<'a> {
pub task_id: u16,
pub task_name: &'a str,
pub host: &'a str,
pub tag_li: &'a [String],
pub duration: u64,
pub msg: String,
}
pub struct Recover<'a> {
pub task_id: u16,
pub task_name: &'a str,
pub host: &'a str,
pub tag_li: &'a [String],
pub duration: u64,
}
macro_rules! display {
($self:ident,$f:ident) => {{
write!($f, " {} : {}", $self.task_name, $self.host)?;
if !$self.tag_li.is_empty() {
write!($f, "( ")?;
for (n, i) in $self.tag_li.iter().enumerate() {
if n > 0 {
write!($f, " / ")?;
}
write!($f, "{}", i)?;
}
write!($f, " )")?;
}
write!($f, "🕝 {}", readable($self.duration))?;
}};
}
impl<'a> Display for Recover<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "✅")?;
display!(self, f);
Ok(())
}
}
impl<'a> Display for Warn<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "❌")?;
display!(self, f);
write!(f, "\n{}", self.msg)?;
Ok(())
}
}