add improved db layout with pkg versions

better error handling of api
This commit is contained in:
2023-12-23 23:00:30 +01:00
parent 9c23bf2411
commit 5bcd8d2ee2
21 changed files with 300 additions and 121 deletions

View File

@@ -1,8 +1,6 @@
use crate::builder::types::Action;
use crate::db::packages;
use crate::db::prelude::Packages;
use crate::repo::repo::add_pkg;
use sea_orm::{ActiveModelTrait, DatabaseConnection, EntityTrait, Set};
use sea_orm::{ActiveModelTrait, DatabaseConnection, Set};
use tokio::sync::broadcast::Sender;
pub async fn init(db: DatabaseConnection, tx: Sender<Action>) {
@@ -10,24 +8,24 @@ pub async fn init(db: DatabaseConnection, tx: Sender<Action>) {
if let Ok(_result) = tx.subscribe().recv().await {
match _result {
// add a package to parallel build
Action::Build(name, version, url, id) => {
Action::Build(name, version, url, mut version_model) => {
let db = db.clone();
// spawn new thread for each pkg build
tokio::spawn(async move {
match add_pkg(url, version, name).await {
Ok(_) => {
Ok(pkg_file_name) => {
println!("successfully built package");
let mut pkg: packages::ActiveModel = Packages::find_by_id(id)
.one(&db)
.await
.unwrap()
.unwrap()
.into();
pkg.status = Set(2);
let pkg: packages::Model = pkg.update(&db).await.unwrap();
// update status
version_model.status = Set(Some(1));
version_model.file_name = Set(Some(pkg_file_name));
version_model.update(&db).await.unwrap();
}
Err(e) => {
version_model.status = Set(Some(2));
version_model.update(&db).await.unwrap();
println!("Error: {e}")
}
}