move worker_task.rs into proxmox-rest-server crate
Also moved pbs-datastore/src/task.rs to pbs-tools, which now depends on 'log'.
This commit is contained in:
@ -9,10 +9,9 @@ use proxmox::tools::fs::{CreateOptions, create_path, create_dir};
|
||||
|
||||
use pbs_api_types::GarbageCollectionStatus;
|
||||
use pbs_tools::process_locker::{self, ProcessLocker};
|
||||
use pbs_tools::{task_log, task::TaskState};
|
||||
|
||||
use crate::DataBlob;
|
||||
use crate::task_log;
|
||||
use crate::task::TaskState;
|
||||
|
||||
/// File system based chunk store
|
||||
pub struct ChunkStore {
|
||||
@ -306,7 +305,7 @@ impl ChunkStore {
|
||||
for (entry, percentage, bad) in self.get_chunk_iterator()? {
|
||||
if last_percentage != percentage {
|
||||
last_percentage = percentage;
|
||||
crate::task_log!(
|
||||
task_log!(
|
||||
worker,
|
||||
"processed {}% ({} chunks)",
|
||||
percentage,
|
||||
|
@ -179,7 +179,6 @@ pub mod paperkey;
|
||||
pub mod prune;
|
||||
pub mod read_chunk;
|
||||
pub mod store_progress;
|
||||
pub mod task;
|
||||
|
||||
pub mod dynamic_index;
|
||||
pub mod fixed_index;
|
||||
|
@ -1,56 +0,0 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! task_error {
|
||||
($task:expr, $($fmt:tt)+) => {{
|
||||
$crate::task::TaskState::log(&*$task, log::Level::Error, &format_args!($($fmt)+))
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! task_warn {
|
||||
($task:expr, $($fmt:tt)+) => {{
|
||||
$crate::task::TaskState::log(&*$task, log::Level::Warn, &format_args!($($fmt)+))
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! task_log {
|
||||
($task:expr, $($fmt:tt)+) => {{
|
||||
$crate::task::TaskState::log(&*$task, log::Level::Info, &format_args!($($fmt)+))
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! task_debug {
|
||||
($task:expr, $($fmt:tt)+) => {{
|
||||
$crate::task::TaskState::log(&*$task, log::Level::Debug, &format_args!($($fmt)+))
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! task_trace {
|
||||
($task:expr, $($fmt:tt)+) => {{
|
||||
$crate::task::TaskState::log(&*$task, log::Level::Trace, &format_args!($($fmt)+))
|
||||
}};
|
||||
}
|
Reference in New Issue
Block a user