From 37657fa6ad841ee110806f0e6353d31269b1f874 Mon Sep 17 00:00:00 2001 From: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Date: Mon, 25 Jul 2022 12:02:41 -0600 Subject: [PATCH] issue notification when individual package restore fails (#1685) --- backend/src/backup/restore.rs | 37 ++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/backend/src/backup/restore.rs b/backend/src/backup/restore.rs index ec58f69e9..889a1f9e3 100644 --- a/backend/src/backup/restore.rs +++ b/backend/src/backup/restore.rs @@ -64,8 +64,39 @@ pub async fn restore_packages_rpc( let (revision, backup_guard, tasks, _) = restore_packages(&ctx, &mut db, backup_guard, ids).await?; - tokio::spawn(async { - futures::future::join_all(tasks).await; + tokio::spawn(async move { + let res = futures::future::join_all(tasks).await; + for res in res { + match res.with_kind(crate::ErrorKind::Unknown) { + Ok((Ok(_), _)) => (), + Ok((Err(err), package_id)) => { + if let Err(err) = ctx.notification_manager.notify( + &mut db, + Some(package_id.clone()), + NotificationLevel::Error, + "Restoration Failure".to_string(), format!("Error restoring package {}: {}", package_id,err), (), None).await{ + tracing::error!("Failed to notify: {}", err); + tracing::debug!("{:?}", err); + }; + tracing::error!("Error restoring package {}: {}", package_id, err); + tracing::debug!("{:?}", err); + }, + Err(e) => { + if let Err(err) = ctx.notification_manager.notify( + &mut db, + None, + NotificationLevel::Error, + "Restoration Failure".to_string(), format!("Error during restoration: {}", e), (), None).await { + + tracing::error!("Failed to notify: {}", err); + tracing::debug!("{:?}", err); + } + tracing::error!("Error restoring packages: {}", e); + tracing::debug!("{:?}", e); + }, + + } + } if let Err(e) = backup_guard.unmount().await { tracing::error!("Error unmounting backup drive: {}", e); tracing::debug!("{:?}", e); @@ -238,7 +269,7 @@ pub async fn recover_full_embassy( &mut db, None, NotificationLevel::Error, - "Restoration Failure".to_string(), format!("Error restoring ?: {}", e), (), None).await { + "Restoration Failure".to_string(), format!("Error during restoration: {}", e), (), None).await { tracing::error!("Failed to notify: {}", err); tracing::debug!("{:?}", err);