mod callback_bridge;
mod progress_verification_wrapper;
use std::fmt::Debug;
use std::sync::Arc;
use async_trait::async_trait;
pub use callback_bridge::{GroupProgressCallbackUpdater, ItemProgressCallbackUpdater, ProgressReporter};
pub use progress_verification_wrapper::ProgressUpdaterVerificationWrapper;
use xet_data::progress_tracking::UniqueID;
#[async_trait]
pub trait TrackingProgressUpdater: Send + Sync {
async fn register_updates(&self, updates: ProgressUpdate);
async fn flush(&self) {}
}
#[derive(Clone, Debug)]
pub struct ItemProgressUpdate {
pub tracking_id: UniqueID,
pub item_name: Arc<str>,
pub total_bytes: u64,
pub bytes_completed: u64,
pub bytes_completion_increment: u64,
}
impl ItemProgressUpdate {
pub fn merge_in(&mut self, other: ItemProgressUpdate) {
debug_assert_eq!(self.tracking_id, other.tracking_id);
debug_assert_eq!(self.item_name, other.item_name);
self.total_bytes = self.total_bytes.max(other.total_bytes);
self.bytes_completed = self.bytes_completed.max(other.bytes_completed);
self.bytes_completion_increment += other.bytes_completion_increment;
}
}
#[derive(Clone, Debug, Default)]
pub struct ProgressUpdate {
pub item_updates: Vec<ItemProgressUpdate>,
pub total_bytes: u64,
pub total_bytes_increment: u64,
pub total_bytes_completed: u64,
pub total_bytes_completion_increment: u64,
pub total_bytes_completion_rate: Option<f64>,
pub total_transfer_bytes: u64,
pub total_transfer_bytes_increment: u64,
pub total_transfer_bytes_completed: u64,
pub total_transfer_bytes_completion_increment: u64,
pub total_transfer_bytes_completion_rate: Option<f64>,
}
impl ProgressUpdate {
pub fn is_empty(&self) -> bool {
self.item_updates.is_empty()
&& self.total_bytes_increment == 0
&& self.total_bytes_completion_increment == 0
&& self.total_transfer_bytes_increment == 0
&& self.total_transfer_bytes_completion_increment == 0
}
pub fn merge_in(&mut self, other: ProgressUpdate) {
self.item_updates.extend(other.item_updates);
self.total_bytes = self.total_bytes.max(other.total_bytes);
self.total_bytes_increment += other.total_bytes_increment;
self.total_bytes_completed = self.total_bytes_completed.max(other.total_bytes_completed);
self.total_bytes_completion_increment += other.total_bytes_completion_increment;
self.total_transfer_bytes = self.total_transfer_bytes.max(other.total_transfer_bytes);
self.total_transfer_bytes_increment += other.total_transfer_bytes_increment;
self.total_transfer_bytes_completed =
self.total_transfer_bytes_completed.max(other.total_transfer_bytes_completed);
self.total_transfer_bytes_completion_increment += other.total_transfer_bytes_completion_increment;
}
}