move TaskState trait to pbs-datastore

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-07-07 09:24:39 +02:00
parent 86fb38776b
commit 155f657f6b
5 changed files with 26 additions and 21 deletions

View File

@ -1,3 +1,5 @@
//! Basic API types used by most of the PBS code.
use proxmox::api::schema::{ApiStringFormat, Schema, StringSchema};
use proxmox::const_regex;

View File

@ -9,6 +9,7 @@ description = "low level pbs data storage access"
anyhow = "1.0"
crc32fast = "1"
endian_trait = { version = "0.6", features = [ "arrays" ] }
log = "0.4"
nix = "0.19.1"
openssl = "0.10"
serde = { version = "1.0", features = ["derive"] }

View File

@ -191,6 +191,7 @@ pub mod data_blob_writer;
pub mod file_formats;
pub mod index;
pub mod key_derivation;
pub mod task;
pub use checksum_reader::ChecksumReader;
pub use checksum_writer::ChecksumWriter;

21
pbs-datastore/src/task.rs Normal file
View File

@ -0,0 +1,21 @@
use anyhow::Error;
/// `WorkerTask` methods commonly used from contexts otherwise not related to the API server.
pub trait TaskState {
/// If the task should be aborted, this should fail with a reasonable error message.
fn check_abort(&self) -> Result<(), Error>;
/// Create a log message for this task.
fn log(&self, level: log::Level, message: &std::fmt::Arguments);
}
/// Convenience implementation:
impl<T: TaskState + ?Sized> TaskState for std::sync::Arc<T> {
fn check_abort(&self) -> Result<(), Error> {
<T as TaskState>::check_abort(&*self)
}
fn log(&self, level: log::Level, message: &std::fmt::Arguments) {
<T as TaskState>::log(&*self, level, message)
}
}

View File

@ -1,24 +1,4 @@
use anyhow::Error;
/// `WorkerTask` methods commonly used from contexts otherwise not related to the API server.
pub trait TaskState {
/// If the task should be aborted, this should fail with a reasonable error message.
fn check_abort(&self) -> Result<(), Error>;
/// Create a log message for this task.
fn log(&self, level: log::Level, message: &std::fmt::Arguments);
}
/// Convenience implementation:
impl<T: TaskState + ?Sized> TaskState for std::sync::Arc<T> {
fn check_abort(&self) -> Result<(), Error> {
<T as TaskState>::check_abort(&*self)
}
fn log(&self, level: log::Level, message: &std::fmt::Arguments) {
<T as TaskState>::log(&*self, level, message)
}
}
pub use pbs_datastore::task::TaskState;
#[macro_export]
macro_rules! task_error {