cli: add timestamp to output

With the Run storing the timestamp, it can be added to the CLI output
as well.

When pretty printing the timestamp, `chrono` is used to have a
date-time format.
This commit is contained in:
Fintan Halpenny
2025-12-28 15:16:29 +00:00
parent c2697d7854
commit e37ff3447e
3 changed files with 22 additions and 2 deletions
Generated
+10
View File
@@ -276,6 +276,15 @@ dependencies = [
"cpufeatures", "cpufeatures",
] ]
[[package]]
name = "chrono"
version = "0.4.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "cipher" name = "cipher"
version = "0.4.4" version = "0.4.4"
@@ -1364,6 +1373,7 @@ dependencies = [
name = "radicle-job" name = "radicle-job"
version = "0.4.0" version = "0.4.0"
dependencies = [ dependencies = [
"chrono",
"clap", "clap",
"indexmap", "indexmap",
"nonempty 0.11.0", "nonempty 0.11.0",
+1
View File
@@ -12,6 +12,7 @@ edition = "2021"
rust-version = "1.84.0" rust-version = "1.84.0"
[dependencies] [dependencies]
chrono = { version = "0.4", default-features = false }
clap = { version = "4.5.41", features = ["derive", "wrap_help"] } clap = { version = "4.5.41", features = ["derive", "wrap_help"] }
indexmap = { version = "2.7.1", features = ["serde"] } indexmap = { version = "2.7.1", features = ["serde"] }
nonempty = "0.11.0" nonempty = "0.11.0"
+11 -2
View File
@@ -3,7 +3,8 @@
//! These can be used in tools that wish to display data, such as the `rad-job` //! These can be used in tools that wish to display data, such as the `rad-job`
//! CLI tool. //! CLI tool.
use radicle::{git::Oid, node::NodeId}; use chrono::Utc;
use radicle::{cob, git::Oid, node::NodeId};
use serde::Serialize; use serde::Serialize;
use url::Url; use url::Url;
use uuid::Uuid; use uuid::Uuid;
@@ -78,6 +79,7 @@ impl Job {
run_id: *run_id, run_id: *run_id,
status: *run.status(), status: *run.status(),
log: run.log().clone(), log: run.log().clone(),
timestamp: *run.timestamp(),
}) })
.collect(); .collect();
runs.sort_by_cached_key(|run| run.run_id); runs.sort_by_cached_key(|run| run.run_id);
@@ -109,7 +111,13 @@ impl Job {
for run in self.runs.iter() { for run in self.runs.iter() {
line(&mut s, format!(" node {}", run.node_id)); line(&mut s, format!(" node {}", run.node_id));
for run2 in run.runs.iter() { for run2 in run.runs.iter() {
line(&mut s, format!(" run {} {:?}", run2.run_id, run2.status)); let date =
chrono::DateTime::<Utc>::from_timestamp_secs(run2.timestamp.as_secs() as i64)
.expect("run timestamp is out of range");
line(
&mut s,
format!(" run {} {:?} [{}]", run2.run_id, run2.status, date),
);
line(&mut s, format!(" log {}", run2.log)); line(&mut s, format!(" log {}", run2.log));
} }
} }
@@ -129,4 +137,5 @@ struct Run {
run_id: Uuid, run_id: Uuid,
status: Status, status: Status,
log: Url, log: Url,
timestamp: cob::Timestamp,
} }