Skip to content

Commit

Permalink
WIP: Add in-progress build state
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 authored and syphar committed Feb 21, 2024
1 parent 1a0ee85 commit 07a121d
Show file tree
Hide file tree
Showing 23 changed files with 339 additions and 123 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions migrations/20240221124844_multi_stage_build_status.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LOCK builds, releases;

DELETE FROM builds WHERE build_status = 'in_progress';

ALTER TABLE builds ALTER build_status
TYPE BOOL
USING build_status = 'success';

DROP TYPE BUILD_STATUS;
13 changes: 13 additions & 0 deletions migrations/20240221124844_multi_stage_build_status.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CREATE TYPE build_status AS ENUM (
'in_progress',
'success',
'failure'
);

ALTER TABLE builds ALTER build_status
TYPE build_status
USING CASE
WHEN build_status
THEN 'success'::build_status
ELSE 'failure'::build_status
END;
14 changes: 8 additions & 6 deletions src/db/add_package.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
db::types::Feature,
docbuilder::{BuildResult, DocCoverage},
db::types::{BuildStatus, Feature},
docbuilder::DocCoverage,
error::Result,
registry_api::{CrateData, CrateOwner, ReleaseData},
storage::CompressionAlgorithm,
Expand Down Expand Up @@ -177,7 +177,9 @@ pub(crate) async fn add_doc_coverage(
pub(crate) async fn add_build_into_database(
conn: &mut sqlx::PgConnection,
release_id: i32,
res: &BuildResult,
rustc_version: &str,
docsrs_version: &str,
build_status: BuildStatus,
) -> Result<i32> {
debug!("Adding build into database");
let hostname = hostname::get()?;
Expand All @@ -186,9 +188,9 @@ pub(crate) async fn add_build_into_database(
VALUES ($1, $2, $3, $4, $5)
RETURNING id",
release_id,
res.rustc_version,
res.docsrs_version,
res.successful,
rustc_version,
docsrs_version,
build_status as BuildStatus,
hostname.to_str().unwrap_or(""),
)
.fetch_one(&mut *conn)
Expand Down
16 changes: 15 additions & 1 deletion src/db/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use postgres_types::{FromSql, ToSql};
use serde::Serialize;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, FromSql, ToSql, sqlx::Type)]
#[postgres(name = "feature")]
Expand All @@ -23,3 +23,17 @@ impl sqlx::postgres::PgHasArrayType for Feature {
sqlx::postgres::PgTypeInfo::with_name("_feature")
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, sqlx::Type)]
#[sqlx(type_name = "build_status", rename_all = "lowercase")]
pub(crate) enum BuildStatus {
Success,
Failure,
InProgress,
}

impl BuildStatus {
pub(crate) fn is_success(&self) -> bool {
matches!(self, BuildStatus::Success)
}
}
2 changes: 1 addition & 1 deletion src/docbuilder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ mod limits;
mod rustwide_builder;

pub(crate) use self::limits::Limits;
pub(crate) use self::rustwide_builder::{BuildResult, DocCoverage};
pub(crate) use self::rustwide_builder::DocCoverage;
pub use self::rustwide_builder::{PackageKind, RustwideBuilder};
12 changes: 10 additions & 2 deletions src/docbuilder/rustwide_builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::db::file::add_path_into_database;
use crate::db::{
add_build_into_database, add_doc_coverage, add_package_into_database,
add_path_into_remote_archive, update_crate_data_in_database, Pool,
add_path_into_remote_archive, types::BuildStatus, update_crate_data_in_database, Pool,
};
use crate::docbuilder::Limits;
use crate::error::Result;
Expand Down Expand Up @@ -580,11 +580,19 @@ impl RustwideBuilder {
))?;
}

let build_status = if res.result.successful {
BuildStatus::Success
} else {
BuildStatus::Failure
};
let build_id = self.runtime.block_on(add_build_into_database(
&mut async_conn,
release_id,
&res.result,
&res.result.rustc_version,
&res.result.docsrs_version,
build_status,
))?;

let build_log_path = format!("build-logs/{build_id}/{default_target}.txt");
self.storage.store_one(build_log_path, res.build_log)?;

Expand Down
Loading

0 comments on commit 07a121d

Please sign in to comment.