diff --git a/airlock_libs/Cargo.lock b/airlock_libs/Cargo.lock index 306a6f0..64e4271 100644 --- a/airlock_libs/Cargo.lock +++ b/airlock_libs/Cargo.lock @@ -26,7 +26,7 @@ dependencies = [ [[package]] name = "airlock_libs" -version = "5.1.2" +version = "5.2.0" dependencies = [ "chrono", "crossbeam", diff --git a/airlock_libs/Cargo.toml b/airlock_libs/Cargo.toml index 7be4866..211f014 100644 --- a/airlock_libs/Cargo.toml +++ b/airlock_libs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "airlock_libs" -version = "5.1.2" +version = "5.2.0" edition = "2024" [lib] diff --git a/airlock_libs/pyproject.toml b/airlock_libs/pyproject.toml index 5e959f4..9c11f5e 100644 --- a/airlock_libs/pyproject.toml +++ b/airlock_libs/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "airlock_libs" -version = "5.1.2" +version = "5.2.0" description = "Airlock Digital API Wrapper" readme = "README.md" license = { text = "AGPL-3.0-only" } diff --git a/airlock_libs/src/modules/datatypes.rs b/airlock_libs/src/modules/datatypes.rs index c27af30..5df65f6 100644 --- a/airlock_libs/src/modules/datatypes.rs +++ b/airlock_libs/src/modules/datatypes.rs @@ -109,4 +109,4 @@ impl SkipBack { let objectid_hex = format!("{}0000000000000000", hex_timestamp); ObjectId::parse_str(&objectid_hex).expect("Invalid ObjectId hex") } -} \ No newline at end of file +} diff --git a/airlock_libs/src/services.rs b/airlock_libs/src/services.rs index 8978738..a0362f9 100644 --- a/airlock_libs/src/services.rs +++ b/airlock_libs/src/services.rs @@ -1,7 +1,8 @@ -use std::thread; -use crossbeam::channel::unbounded; use crate::modules::datatypes::*; use crate::prelude::*; +use crossbeam::channel::unbounded; +use std::sync::{Arc, Mutex}; +use std::thread; #[pyfunction] pub fn pull_policy_exec_histories( py: Python<'_>, @@ -72,15 +73,16 @@ pub fn pull_policy_exec_histories( } } let mut checkpoint_number: String = SkipBack::find_checkpoint(days).to_string(); - let multi_progress: MultiProgress = MultiProgress::new(); - multi_progress.set_draw_target(ProgressDrawTarget::stderr()); - let progress_bar: ProgressBar = multi_progress.add(ProgressBar::new(100)); - progress_bar.set_style( + let progress_bar = Arc::new(Mutex::new(ProgressBar::new(100))); + progress_bar + .lock() + .unwrap() + .set_draw_target(ProgressDrawTarget::stderr()); + progress_bar.lock().unwrap().set_style( ProgressStyle::default_bar() .template("Total Completion: {spinner:.green} [{elapsed_precise}] [{bar:40.green/blue}] {pos}/{len} {message}") .unwrap(), ); - progress_bar.enable_steady_tick(std::time::Duration::from_millis(100)); let client: Client = tracer.in_span("Building HTTP Client", |cx| { let client_result: Result = build_client(headers); match client_result { @@ -111,6 +113,7 @@ pub fn pull_policy_exec_histories( }); let cutoff: chrono::NaiveDateTime = Local::now().naive_local() - Duration::days(days); let (tx, rx) = unbounded::>(); + let pb_clone = progress_bar.clone(); thread::spawn(move || { let mut seen: HashMap<(String, String, String), Group> = if writeable_filepath.exists() { @@ -178,6 +181,10 @@ pub fn pull_policy_exec_histories( }); let mut first_date: Option = None; tracer.in_span("Airlock Data Retreival", |cx| { + pb_clone + .lock() + .unwrap() + .enable_steady_tick(std::time::Duration::from_millis(100)); let span: opentelemetry::trace::SpanRef<'_> = cx.span(); span.set_attribute(Key::new("Days").string(days.to_string())); span.set_attribute(KeyValue::new("Policy Name", policy_names.clone())); @@ -213,16 +220,21 @@ pub fn pull_policy_exec_histories( } if let Some(base_date) = first_date { let date_diff: chrono::TimeDelta = last_date - base_date; - let total_span: i64 = (Local::now().naive_local().date() - base_date).num_days(); - let percentage: u64 = ((date_diff.num_days() as f64 / total_span as f64) * 100.0) + let total_span: i64 = + (Local::now().naive_local().date() - base_date).num_days(); + let percentage: u64 = ((date_diff.num_days() as f64 / total_span as f64) + * 100.0) .clamp(0.0, 100.0) .round() as u64; - progress_bar.set_position(percentage); + pb_clone.lock().unwrap().set_position(percentage); } } } }); - progress_bar.finish_with_message("All Checkpoints Complete"); + progress_bar + .lock() + .unwrap() + .finish_with_message("All Checkpoints Complete"); let return_data: String = match fs::read_to_string(file_path.clone()) { Ok(return_data) => return_data, Err(e) => { diff --git a/requirements.txt b/requirements.txt index ada2a2d..b11687f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,4 +11,4 @@ urllib3==2.5.0 pyperclip==1.11.0 --extra-index-url https://git.racooncity.org/api/packages/brotoskyj/pypi/simple/ -airlock_libs==5.1.2 \ No newline at end of file +airlock_libs==5.2.0 \ No newline at end of file