aboutsummaryrefslogtreecommitdiff
path: root/import/src/reporting.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-12-10 17:52:41 +0100
committermetamuffin <metamuffin@disroot.org>2025-12-10 17:52:41 +0100
commite4f865e9da9d6660399e22a6fbeb5b84a749b07a (patch)
tree4af69589e8850d8a2b0c88a10e43efe8c79cb8dc /import/src/reporting.rs
parenta0cfd77b4d19c43a28c4d82072e6ff136e336af3 (diff)
downloadjellything-e4f865e9da9d6660399e22a6fbeb5b84a749b07a.tar
jellything-e4f865e9da9d6660399e22a6fbeb5b84a749b07a.tar.bz2
jellything-e4f865e9da9d6660399e22a6fbeb5b84a749b07a.tar.zst
refactor import plugins part 2
Diffstat (limited to 'import/src/reporting.rs')
-rw-r--r--import/src/reporting.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/import/src/reporting.rs b/import/src/reporting.rs
new file mode 100644
index 0000000..3105b59
--- /dev/null
+++ b/import/src/reporting.rs
@@ -0,0 +1,46 @@
+/*
+ This file is part of jellything (https://codeberg.org/metamuffin/jellything)
+ which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
+ Copyright (C) 2025 metamuffin <metamuffin.org>
+*/
+
+use anyhow::Result;
+use rayon::{current_num_threads, current_thread_index};
+use tokio::sync::RwLock;
+
+pub static IMPORT_ERRORS: RwLock<Vec<String>> = RwLock::const_new(Vec::new());
+pub static IMPORT_PROGRESS: RwLock<Option<ImportProgress>> = RwLock::const_new(None);
+
+pub struct ImportProgress {
+ pub total_items: usize,
+ pub finished_items: usize,
+ pub tasks: Vec<String>,
+}
+
+pub(crate) fn start_import() {
+ *IMPORT_ERRORS.blocking_write() = Vec::new();
+ *IMPORT_PROGRESS.blocking_write() = Some(ImportProgress {
+ total_items: 0,
+ finished_items: 0,
+ tasks: vec!["idle".to_string(); current_num_threads()],
+ });
+}
+pub(crate) fn end_import() {
+ *IMPORT_PROGRESS.blocking_write() = None;
+}
+
+pub(crate) fn set_task(task: String) {
+ if let Some(p) = IMPORT_PROGRESS.blocking_write().as_mut() {
+ p.tasks[current_thread_index().unwrap_or(0)] = task
+ }
+}
+
+pub(crate) fn catch<T>(res: Result<T>) -> Option<T> {
+ match res {
+ Ok(res) => Some(res),
+ Err(e) => {
+ IMPORT_ERRORS.blocking_write().push(format!("{e:#}"));
+ None
+ }
+ }
+}