From d409d08572fa8d61e7a76b8124c6772b8f573310 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Tue, 26 Dec 2023 23:14:00 +0100 Subject: [PATCH] set status correctly --- Dockerfile | 5 ----- src/builder/builder.rs | 22 ++++++++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index ef63db1..a5c9272 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,11 +24,6 @@ RUN pacman -Syyu --noconfirm RUN pacman -S --noconfirm base-devel git RUN pacman -Sc -# Set any additional configurations or dependencies if required - -# Example: Expose a port if your application listens on a specific port -# EXPOSE 8080 - # Set the entry point or default command to run your application WORKDIR /app CMD ["untitled"] diff --git a/src/builder/builder.rs b/src/builder/builder.rs index 4e9efa4..1fc1c06 100644 --- a/src/builder/builder.rs +++ b/src/builder/builder.rs @@ -24,7 +24,7 @@ pub async fn init(db: DatabaseConnection, tx: Sender) { status: Set(Some(0)), ..Default::default() }; - let new_build = build.save(&db).await.unwrap(); + let mut new_build = build.save(&db).await.unwrap(); // spawn new thread for each pkg build // todo add queue and build two packages in parallel @@ -32,6 +32,7 @@ pub async fn init(db: DatabaseConnection, tx: Sender) { let (tx, mut rx) = broadcast::channel::(3); let db2 = db.clone(); + let new_build2 = new_build.clone(); tokio::spawn(async move { loop { match rx.recv().await { @@ -41,7 +42,7 @@ pub async fn init(db: DatabaseConnection, tx: Sender) { let _ = append_db_log_output( &db2, output_line, - new_build.id.clone().unwrap(), + new_build2.id.clone().unwrap(), ) .await; } @@ -67,6 +68,10 @@ pub async fn init(db: DatabaseConnection, tx: Sender) { version_model.file_name = Set(Some(pkg_file_name)); let _ = version_model.update(&db).await; + + new_build.status = Set(Some(1)); + let _ = new_build.update(&db).await; + } Err(e) => { let _ = set_pkg_status( @@ -77,6 +82,9 @@ pub async fn init(db: DatabaseConnection, tx: Sender) { .await; let _ = version_model.update(&db).await; + new_build.status = Set(Some(1)); + let _ = new_build.update(&db).await; + println!("Error: {e}") } } @@ -93,15 +101,13 @@ async fn set_pkg_status( package_id: i32, status: i32, ) -> anyhow::Result<()> { - let mut pkg = Packages::find_by_id(package_id) + let mut pkg: packages::ActiveModel = Packages::find_by_id(package_id) .one(db) .await? - .ok_or(anyhow!("no package with id {package_id} found"))?; - - pkg.status = status; - - let pkg: packages::ActiveModel = pkg.into(); + .ok_or(anyhow!("no package with id {package_id} found"))? + .into(); + pkg.status = Set(status); pkg.update(db).await?; Ok(()) }