diff --git a/DESIGN.md b/DESIGN.md index 097b12c..5cae34f 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -50,6 +50,13 @@ Job result: 1. List of successful builds 2. Failed package and link to build log (on buildit.aosc.io) +Job status: + +1. created: can be assigned to worker +2. assigned: assigned to worker +3. error: unexpected error +4. finished: finished, successful or failed + ## Authentication Authentication: diff --git a/server/migrations/2024-03-10-154337_add_error_message_to_jobs/down.sql b/server/migrations/2024-03-10-154337_add_error_message_to_jobs/down.sql new file mode 100644 index 0000000..54e5cee --- /dev/null +++ b/server/migrations/2024-03-10-154337_add_error_message_to_jobs/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE jobs DROP COLUMN error_message; diff --git a/server/migrations/2024-03-10-154337_add_error_message_to_jobs/up.sql b/server/migrations/2024-03-10-154337_add_error_message_to_jobs/up.sql new file mode 100644 index 0000000..b628ca1 --- /dev/null +++ b/server/migrations/2024-03-10-154337_add_error_message_to_jobs/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE jobs ADD COLUMN error_message TEXT; diff --git a/server/migrations/2024-03-10-155259_add_elapsed_secs_to_jobs/down.sql b/server/migrations/2024-03-10-155259_add_elapsed_secs_to_jobs/down.sql new file mode 100644 index 0000000..c2a6905 --- /dev/null +++ b/server/migrations/2024-03-10-155259_add_elapsed_secs_to_jobs/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE jobs DROP COLUMN elapsed_secs; diff --git a/server/migrations/2024-03-10-155259_add_elapsed_secs_to_jobs/up.sql b/server/migrations/2024-03-10-155259_add_elapsed_secs_to_jobs/up.sql new file mode 100644 index 0000000..8439a7c --- /dev/null +++ b/server/migrations/2024-03-10-155259_add_elapsed_secs_to_jobs/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE jobs ADD COLUMN elapsed_secs BIGINT; diff --git a/server/src/models.rs b/server/src/models.rs index 73152a4..566d8eb 100644 --- a/server/src/models.rs +++ b/server/src/models.rs @@ -48,6 +48,8 @@ pub struct Job { pub skipped_packages: Option, pub log_url: Option, pub finish_time: Option>, + pub error_message: Option, + pub elapsed_secs: Option, } #[derive(Insertable)] diff --git a/server/src/routes.rs b/server/src/routes.rs index f24d9ea..5c67ab4 100644 --- a/server/src/routes.rs +++ b/server/src/routes.rs @@ -189,7 +189,7 @@ pub enum JobResult { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct JobOk { /// Is the build successful? - pub success: bool, + pub build_success: bool, /// List of packages successfully built pub successful_packages: Vec, /// List of packages failed to build @@ -197,9 +197,9 @@ pub struct JobOk { /// List of packages skipped pub skipped_packages: Vec, /// URL to build log - pub log: Option, + pub log_url: Option, /// Elapsed time of the job - pub elapsed: Duration, + pub elapsed_secs: i64, /// If pushpkg succeeded pub pushpkg_success: bool, } @@ -216,5 +216,32 @@ pub async fn worker_job_update( State(pool): State, Json(payload): Json, ) -> Result<(), AnyhowError> { + let mut conn = pool + .get() + .context("Failed to get db connection from pool")?; + + use crate::schema::jobs::dsl::*; + match payload.result { + JobResult::Ok(res) => { + diesel::update(jobs.filter(id.eq(payload.job_id))) + .set(( + status.eq("finished"), + build_success.eq(res.build_success), + pushpkg_success.eq(res.pushpkg_success), + successful_packages.eq(res.successful_packages.join(",")), + failed_package.eq(res.failed_package), + skipped_packages.eq(res.skipped_packages.join(",")), + log_url.eq(res.log_url), + finish_time.eq(chrono::Utc::now()), + elapsed_secs.eq(res.elapsed_secs), + )) + .execute(&mut conn)?; + } + JobResult::Error(err) => { + diesel::update(jobs.filter(id.eq(payload.job_id))) + .set((status.eq("error"), error_message.eq(err))) + .execute(&mut conn)?; + } + } Ok(()) } diff --git a/server/src/schema.rs b/server/src/schema.rs index 1aa6b3a..552daef 100644 --- a/server/src/schema.rs +++ b/server/src/schema.rs @@ -16,6 +16,8 @@ diesel::table! { skipped_packages -> Nullable, log_url -> Nullable, finish_time -> Nullable, + error_message -> Nullable, + elapsed_secs -> Nullable, } } @@ -47,4 +49,8 @@ diesel::table! { diesel::joinable!(jobs -> pipelines (pipeline_id)); -diesel::allow_tables_to_appear_in_same_query!(jobs, pipelines, workers,); +diesel::allow_tables_to_appear_in_same_query!( + jobs, + pipelines, + workers, +);