From 155f657f6bfe801ca3d6b9ad3346982dd9600601 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 7 Jul 2021 09:24:39 +0200 Subject: [PATCH] move TaskState trait to pbs-datastore Signed-off-by: Wolfgang Bumiller --- pbs-api-types/src/lib.rs | 2 ++ pbs-datastore/Cargo.toml | 1 + pbs-datastore/src/lib.rs | 1 + pbs-datastore/src/task.rs | 21 +++++++++++++++++++++ src/task.rs | 22 +--------------------- 5 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 pbs-datastore/src/task.rs diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs index 0e3d5c39..108c2ee2 100644 --- a/pbs-api-types/src/lib.rs +++ b/pbs-api-types/src/lib.rs @@ -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; diff --git a/pbs-datastore/Cargo.toml b/pbs-datastore/Cargo.toml index eed3a1d7..e66a9bb9 100644 --- a/pbs-datastore/Cargo.toml +++ b/pbs-datastore/Cargo.toml @@ -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"] } diff --git a/pbs-datastore/src/lib.rs b/pbs-datastore/src/lib.rs index c6981cc1..09ba0103 100644 --- a/pbs-datastore/src/lib.rs +++ b/pbs-datastore/src/lib.rs @@ -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; diff --git a/pbs-datastore/src/task.rs b/pbs-datastore/src/task.rs new file mode 100644 index 00000000..91a6bb11 --- /dev/null +++ b/pbs-datastore/src/task.rs @@ -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 TaskState for std::sync::Arc { + fn check_abort(&self) -> Result<(), Error> { + ::check_abort(&*self) + } + + fn log(&self, level: log::Level, message: &std::fmt::Arguments) { + ::log(&*self, level, message) + } +} diff --git a/src/task.rs b/src/task.rs index 8cfd6fe8..69498e20 100644 --- a/src/task.rs +++ b/src/task.rs @@ -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 TaskState for std::sync::Arc { - fn check_abort(&self) -> Result<(), Error> { - ::check_abort(&*self) - } - - fn log(&self, level: log::Level, message: &std::fmt::Arguments) { - ::log(&*self, level, message) - } -} +pub use pbs_datastore::task::TaskState; #[macro_export] macro_rules! task_error {