Feature/issue notifications (#695)

* issues notification for installation failure

* issues notification for uninstall failure

* fixes notification api
This commit is contained in:
Keagan McClelland
2021-10-27 16:15:14 -06:00
committed by Aiden McClelland
parent 1e7492e915
commit 5eca577152

View File

@@ -32,6 +32,7 @@ use crate::dependencies::{
};
use crate::install::cleanup::{cleanup, update_dependents};
use crate::install::progress::{InstallProgress, InstallProgressTracker};
use crate::notifications::NotificationLevel;
use crate::s9pk::manifest::{Manifest, PackageId};
use crate::s9pk::reader::S9pkReader;
use crate::status::{MainStatus, Status};
@@ -135,9 +136,27 @@ pub async fn install(
drop(db_handle);
tokio::spawn(async move {
let mut db_handle = ctx.db.handle();
if let Err(e) = download_install_s9pk(&ctx, &man, s9pk).await {
tracing::error!("Install of {}@{} Failed: {}", man.id, man.version, e);
let err_str = format!("Install of {}@{} Failed: {}", man.id, man.version, e);
tracing::error!("{}", err_str);
tracing::debug!("{:?}", e);
if let Err(e) = ctx
.notification_manager
.notify(
&mut db_handle,
Some(man.id),
NotificationLevel::Error,
String::from("Install Failed"),
err_str,
(),
None,
)
.await
{
tracing::error!("Failed to issue Notification: {}", e);
tracing::debug!("{:?}", e);
}
}
});
@@ -203,8 +222,25 @@ pub async fn uninstall_impl(ctx: RpcContext, id: PackageId) -> Result<WithRevisi
tokio::spawn(async move {
if let Err(e) = cleanup::uninstall(&ctx, &mut ctx.db.handle(), &installed).await {
tracing::error!("Uninstall of {} Failed: {}", id, e);
let err_str = format!("Uninstall of {} Failed: {}", id, e);
tracing::error!("{}", err_str);
tracing::debug!("{:?}", e);
if let Err(e) = ctx
.notification_manager
.notify(
&mut ctx.db.handle(), // allocating separate handle here because the lifetime of the previous one is the expression
Some(id),
NotificationLevel::Error,
String::from("Uninstall Failed"),
err_str,
(),
None,
)
.await
{
tracing::error!("Failed to issue Notification: {}", e);
tracing::debug!("{:?}", e);
}
}
});