introduce TaskState trait

Used to not require access to the WorkerTask struct outside
the `server` and `api2` module, so it'll be easier to
separate those backup/server/client parts into separate
crates.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller
2020-10-12 11:28:03 +02:00
parent adfcfb6788
commit d1993187b6
3 changed files with 74 additions and 0 deletions

View File

@ -851,3 +851,19 @@ impl WorkerTask {
&self.upid
}
}
impl crate::task::TaskState for WorkerTask {
fn check_abort(&self) -> Result<(), Error> {
self.fail_on_abort()
}
fn log(&self, level: log::Level, message: &std::fmt::Arguments) {
match level {
log::Level::Error => self.warn(&message.to_string()),
log::Level::Warn => self.warn(&message.to_string()),
log::Level::Info => self.log(&message.to_string()),
log::Level::Debug => self.log(&format!("DEBUG: {}", message)),
log::Level::Trace => self.log(&format!("TRACE: {}", message)),
}
}
}