hive-sh4re/hive-bash-mcp/hive-agent: retype TaskFile timestamps to DateTime<Utc>, drop now_unix from these crates

This commit is contained in:
damocles 2026-08-01 21:34:29 +02:00 committed by mara
commit 2122e23d81
7 changed files with 30 additions and 22 deletions

View file

@ -38,11 +38,12 @@ fn format_task(task: &TaskFile) -> String {
let _ = write!(out, ", exit={code}");
}
if let (Some(started), None) = (task.started_at, task.completed_at) {
let now = hive_sh4re::wire_time::now_unix();
let _ = write!(out, ", running for {}s", now - started);
let elapsed = (chrono::Utc::now() - started).num_seconds();
let _ = write!(out, ", running for {elapsed}s");
}
if let (Some(completed), Some(started)) = (task.completed_at, task.started_at) {
let _ = write!(out, ", took {}s", completed - started);
let took = (completed - started).num_seconds();
let _ = write!(out, ", took {took}s");
}
let out_file = crate::paths::task_out(&task.id);
@ -295,8 +296,8 @@ mod status_hint_tests {
cmd: "echo hi".to_owned(),
timeout_secs: None,
status,
created_at: 1,
started_at: Some(1),
created_at: chrono::DateTime::from_timestamp(1, 0).unwrap_or_default(),
started_at: Some(chrono::DateTime::from_timestamp(1, 0).unwrap_or_default()),
completed_at: None,
exit_code: None,
stdout_tail: None,

View file

@ -133,8 +133,6 @@ fn signal_group(pgid: Option<i32>, sig: i32) {
// Helpers
// ---------------------------------------------------------------------------
use hive_sh4re::wire_time::now_unix;
/// Generate a task ID: `<timestamp_hex><seq_hex>`.
#[must_use]
pub fn new_task_id() -> String {
@ -271,7 +269,7 @@ pub fn submit_task(cmd: String, timeout_secs: Option<u64>, name: Option<String>)
cmd,
timeout_secs,
status: TaskStatus::Pending,
created_at: now_unix(),
created_at: chrono::Utc::now(),
started_at: None,
completed_at: None,
exit_code: None,
@ -377,7 +375,7 @@ pub fn kill_task(id: &str, force: bool) -> (bool, bool) {
&& task.status == TaskStatus::Pending
{
task.status = TaskStatus::Killed;
task.completed_at = Some(now_unix());
task.completed_at = Some(chrono::Utc::now());
let _ = write_task(&task);
// A Pending task never reached Running, so it has no keyed "active"
// todo to clear and (like the old code) fires no completion signal —
@ -435,7 +433,7 @@ async fn mark_interrupted(socket: &Path) {
}
tracing::warn!(id = %id, "bash_runner: marking interrupted task");
task.status = TaskStatus::Interrupted;
task.completed_at = Some(now_unix());
task.completed_at = Some(chrono::Utc::now());
if let Err(e) = write_task(&task) {
tracing::warn!(id = %id, error = ?e, "bash_runner: write interrupted state failed");
}
@ -490,7 +488,7 @@ async fn run_task(mut task: TaskFile, socket: &Path) {
tracing::info!(id = %id, cmd = %task.cmd, "bash_runner: starting task");
task.status = TaskStatus::Running;
task.started_at = Some(now_unix());
task.started_at = Some(chrono::Utc::now());
if let Err(e) = write_task(&task) {
tracing::warn!(id = %id, error = ?e, "bash_runner: write running state failed");
}
@ -559,7 +557,7 @@ async fn run_task(mut task: TaskFile, socket: &Path) {
};
task.status = status;
task.completed_at = Some(now_unix());
task.completed_at = Some(chrono::Utc::now());
task.exit_code = exit_code;
task.stdout_tail = stdout_tail.clone().filter(|s| !s.is_empty());
task.stderr_tail = stderr_tail.clone().filter(|s| !s.is_empty());