Write the build start to the database.
This commit is contained in:
@@ -94,6 +94,7 @@ async fn build_target(
|
||||
build_directory,
|
||||
flake_directory,
|
||||
target_config.get_attr()?,
|
||||
target_config.get_name()?,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -121,6 +121,11 @@ impl TargetConfig {
|
||||
pub(crate) fn get_attr(&'_ self) -> Result<&String, CustomError> {
|
||||
Ok(&self.attr)
|
||||
}
|
||||
|
||||
/// The name to identify this target
|
||||
pub(crate) fn get_name(&'_ self) -> Result<&String, CustomError> {
|
||||
Ok(&self.name)
|
||||
}
|
||||
}
|
||||
|
||||
fn hex_string(data: &[u8]) -> String {
|
||||
|
||||
@@ -10,16 +10,18 @@ use crate::database::db_handle::DbHandle;
|
||||
|
||||
use super::running_build::RunningBuild;
|
||||
|
||||
pub(crate) async fn nixos_build_target<B, F, A>(
|
||||
pub(crate) async fn nixos_build_target<B, F, A, TN>(
|
||||
db_handle: &DbHandle,
|
||||
build_path: B,
|
||||
flake_path: F,
|
||||
attr: A,
|
||||
target_name: TN,
|
||||
) -> Result<()>
|
||||
where
|
||||
B: AsRef<Path>,
|
||||
F: AsRef<Path>,
|
||||
A: AsRef<str>,
|
||||
TN: AsRef<str>,
|
||||
{
|
||||
let reference = {
|
||||
let path = AsRef::<OsStr>::as_ref(flake_path.as_ref());
|
||||
@@ -55,7 +57,7 @@ where
|
||||
let child = command.spawn()?;
|
||||
|
||||
let mut running_build = RunningBuild::new(db_handle)?;
|
||||
running_build.run_to_completion(child).await?;
|
||||
running_build.run_to_completion(child, target_name).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use sqlx::Row;
|
||||
use tokio::io::AsyncBufReadExt;
|
||||
use tokio::io::BufReader;
|
||||
use tokio::io::Lines;
|
||||
@@ -17,7 +18,22 @@ impl<'db> RunningBuild<'db> {
|
||||
Ok(RunningBuild { db_handle })
|
||||
}
|
||||
|
||||
pub(crate) async fn run_to_completion(&mut self, mut child: Child) -> Result<()> {
|
||||
pub(crate) async fn run_to_completion<TN>(
|
||||
&mut self,
|
||||
mut child: Child,
|
||||
target_name: TN,
|
||||
) -> Result<()>
|
||||
where
|
||||
TN: AsRef<str>,
|
||||
{
|
||||
let build_id: i64 = sqlx::query(
|
||||
r#"INSERT INTO build (start_time, target) SELECT unixepoch('now'), ? RETURNING id"#,
|
||||
)
|
||||
.bind(target_name.as_ref())
|
||||
.fetch_one(&self.db_handle.conn)
|
||||
.await?
|
||||
.try_get("id")?;
|
||||
|
||||
let mut output_stream = OutputStream::from_child(&mut child)?;
|
||||
|
||||
let exit_status_handle = tokio::spawn(async move {
|
||||
@@ -41,6 +57,19 @@ impl<'db> RunningBuild<'db> {
|
||||
let exit_status = exit_status_handle.await?;
|
||||
println!("nixos-rebuild status was: {}", exit_status);
|
||||
|
||||
let update: u64 =
|
||||
sqlx::query(r#"UPDATE build SET end_time=unixepoch('now'), status=? WHERE id=?"#)
|
||||
.bind(
|
||||
exit_status
|
||||
.code()
|
||||
.expect("Process should have an exit code."),
|
||||
)
|
||||
.bind(build_id)
|
||||
.execute(&self.db_handle.conn)
|
||||
.await?
|
||||
.rows_affected();
|
||||
assert!(update == 1);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user