Write the build start to the database.
This commit is contained in:
@@ -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