mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
fix HasModel for ServerInfo
This commit is contained in:
committed by
Aiden McClelland
parent
f4b70f653f
commit
ee8eca7038
@@ -51,6 +51,7 @@ impl Database {
|
||||
clearnet: Vec::new(),
|
||||
},
|
||||
share_stats: false,
|
||||
update_progress: None,
|
||||
},
|
||||
package_data: AllPackageData::default(),
|
||||
broken_packages: Vec::new(),
|
||||
@@ -71,7 +72,6 @@ pub struct ServerInfo {
|
||||
pub version: Version,
|
||||
pub lan_address: Url,
|
||||
pub tor_address: Url,
|
||||
#[serde(flatten)]
|
||||
pub status: ServerStatus,
|
||||
pub eos_marketplace: Url,
|
||||
pub package_marketplace: Option<Url>, // None implies use eos_marketplace
|
||||
@@ -79,18 +79,15 @@ pub struct ServerInfo {
|
||||
pub unread_notification_count: u64,
|
||||
pub connection_addresses: ConnectionAddresses,
|
||||
pub share_stats: bool,
|
||||
pub update_progress: Option<UpdateProgress>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
#[serde(tag = "status")]
|
||||
pub enum ServerStatus {
|
||||
Running {},
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
Updating {
|
||||
update_progress: UpdateProgress,
|
||||
},
|
||||
BackingUp {},
|
||||
Running,
|
||||
Updating,
|
||||
BackingUp,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
||||
@@ -165,12 +165,11 @@ async fn maybe_do_update(ctx: RpcContext) -> Result<Option<Arc<Revision>>, Error
|
||||
}
|
||||
let mut db = ctx.db.handle();
|
||||
let mut tx = db.begin().await?;
|
||||
let mut status = crate::db::DatabaseModel::new()
|
||||
let mut info = crate::db::DatabaseModel::new()
|
||||
.server_info()
|
||||
.status()
|
||||
.get_mut(&mut tx)
|
||||
.await?;
|
||||
match &*status {
|
||||
match &info.status {
|
||||
ServerStatus::Updating { .. } => {
|
||||
return Err(Error::new(
|
||||
anyhow!("Server is already updating!"),
|
||||
@@ -197,13 +196,12 @@ async fn maybe_do_update(ctx: RpcContext) -> Result<Option<Arc<Revision>>, Error
|
||||
new_label,
|
||||
)
|
||||
.await?;
|
||||
*status = ServerStatus::Updating {
|
||||
update_progress: UpdateProgress {
|
||||
size,
|
||||
downloaded: 0,
|
||||
},
|
||||
};
|
||||
status.save(&mut tx).await?;
|
||||
info.status = ServerStatus::Updating;
|
||||
info.update_progress = Some(UpdateProgress {
|
||||
size,
|
||||
downloaded: 0,
|
||||
});
|
||||
info.save(&mut tx).await?;
|
||||
let rev = tx.commit(None).await?;
|
||||
|
||||
tokio::spawn(async move {
|
||||
@@ -211,19 +209,14 @@ async fn maybe_do_update(ctx: RpcContext) -> Result<Option<Arc<Revision>>, Error
|
||||
Ok(()) => todo!("issue notification"),
|
||||
Err(e) => {
|
||||
let mut db = ctx.db.handle();
|
||||
let mut status = crate::db::DatabaseModel::new()
|
||||
let mut info = crate::db::DatabaseModel::new()
|
||||
.server_info()
|
||||
.status()
|
||||
.get_mut(&mut db)
|
||||
.await
|
||||
.expect("could not access status");
|
||||
*status = ServerStatus::Updating {
|
||||
update_progress: UpdateProgress {
|
||||
size,
|
||||
downloaded: 0,
|
||||
},
|
||||
};
|
||||
status.save(&mut db).await.expect("could not save status");
|
||||
info.status = ServerStatus::Running;
|
||||
info.update_progress = None;
|
||||
info.save(&mut db).await.expect("could not save status");
|
||||
|
||||
todo!("{}, issue notification", e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user