Only print status when activities change or enough time has passed.
This commit is contained in:
@@ -2,6 +2,7 @@ use std::fmt::Display;
|
||||
use std::num::TryFromIntError;
|
||||
use std::str::Utf8Error;
|
||||
use std::string::FromUtf8Error;
|
||||
use std::time::SystemTimeError;
|
||||
|
||||
use crate::nix_util::ActivityIdAlreadyInTreeError;
|
||||
use crate::nix_util::ActivityIdNotInTreeError;
|
||||
@@ -24,6 +25,7 @@ pub(crate) enum CustomError {
|
||||
TryFromIntError(#[allow(dead_code)] TryFromIntError),
|
||||
ActivityIdNotInTreeError(#[allow(dead_code)] ActivityIdNotInTreeError),
|
||||
ActivityIdAlreadyInTreeError(#[allow(dead_code)] ActivityIdAlreadyInTreeError),
|
||||
SystemTime(#[allow(dead_code)] SystemTimeError),
|
||||
}
|
||||
|
||||
impl Display for CustomError {
|
||||
@@ -127,3 +129,9 @@ impl From<ActivityIdAlreadyInTreeError> for CustomError {
|
||||
CustomError::ActivityIdAlreadyInTreeError(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SystemTimeError> for CustomError {
|
||||
fn from(value: SystemTimeError) -> Self {
|
||||
CustomError::SystemTime(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::borrow::Cow;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use sqlx::Row;
|
||||
use tokio::process::Child;
|
||||
@@ -37,6 +40,7 @@ use super::nix_output_stream::NixMessage;
|
||||
pub(crate) struct RunningBuild<'db> {
|
||||
db_handle: &'db DbHandle,
|
||||
activity_tree: ActivityTree,
|
||||
last_announce: Option<Instant>,
|
||||
}
|
||||
|
||||
impl<'db> RunningBuild<'db> {
|
||||
@@ -44,6 +48,7 @@ impl<'db> RunningBuild<'db> {
|
||||
Ok(RunningBuild {
|
||||
db_handle,
|
||||
activity_tree: ActivityTree::new(),
|
||||
last_announce: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -55,6 +60,8 @@ impl<'db> RunningBuild<'db> {
|
||||
where
|
||||
TN: AsRef<str>,
|
||||
{
|
||||
let foo = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
|
||||
let now = Instant::now();
|
||||
let build_id: i64 = sqlx::query(
|
||||
r#"INSERT INTO build (start_time, target) SELECT unixepoch('now'), ? RETURNING id"#,
|
||||
)
|
||||
@@ -318,7 +325,7 @@ impl<'db> RunningBuild<'db> {
|
||||
activity_result_progress.failed,
|
||||
);
|
||||
|
||||
self.print_current_status();
|
||||
self.maybe_print_current_status();
|
||||
}
|
||||
ActivityResultMessage::SetExpected(activity_result_set_expected) => {
|
||||
let activity_id = self
|
||||
@@ -329,7 +336,7 @@ impl<'db> RunningBuild<'db> {
|
||||
.get_mut_activity()
|
||||
.set_expected(activity_result_set_expected.expected);
|
||||
|
||||
self.print_current_status();
|
||||
self.maybe_print_current_status();
|
||||
}
|
||||
ActivityResultMessage::PostBuildLogLine(
|
||||
_activity_result_post_build_log_line,
|
||||
@@ -341,7 +348,23 @@ impl<'db> RunningBuild<'db> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_current_status(&self) -> () {
|
||||
fn maybe_print_current_status(&mut self) -> () {
|
||||
let last_announce = match self.last_announce {
|
||||
Some(instant) => instant,
|
||||
None => {
|
||||
// If we haven't announced before, always announce.
|
||||
return self.print_current_status();
|
||||
}
|
||||
};
|
||||
|
||||
let now = Instant::now();
|
||||
let time_since_last_announce = now.duration_since(last_announce);
|
||||
if time_since_last_announce > Duration::new(5, 0) {
|
||||
return self.print_current_status();
|
||||
}
|
||||
}
|
||||
|
||||
fn print_current_status(&mut self) -> () {
|
||||
let mut tree = String::new();
|
||||
let draw_order = self.get_draw_order();
|
||||
for dag_entry in draw_order {
|
||||
@@ -378,6 +401,7 @@ impl<'db> RunningBuild<'db> {
|
||||
} else {
|
||||
print!("\n{}\n", tree);
|
||||
}
|
||||
self.last_announce = Some(Instant::now());
|
||||
}
|
||||
|
||||
fn get_draw_order(&self) -> Vec<DrawDagEntry> {
|
||||
|
||||
Reference in New Issue
Block a user