summaryrefslogtreecommitdiffstats
path: root/src/commands/db.rs
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-05-10 14:36:35 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-05-10 14:37:12 +0200
commitfc9635a3d392925f95175ab8a9c89a02debe269c (patch)
treed1bb252fc621896721194ec754a17ba578077a6d /src/commands/db.rs
parentb56aa86b161edf12f7d0b01c05e76758e3e8bd94 (diff)
Add subcommand "db log-of"
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/commands/db.rs')
-rw-r--r--src/commands/db.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/commands/db.rs b/src/commands/db.rs
index a4f9f3e..4c65d09 100644
--- a/src/commands/db.rs
+++ b/src/commands/db.rs
@@ -27,6 +27,7 @@ use diesel::RunQueryDsl;
use itertools::Itertools;
use log::debug;
use log::info;
+use resiter::AndThen;
use crate::config::Configuration;
use crate::db::models;
@@ -50,6 +51,7 @@ pub fn db(
Some(("submits", matches)) => submits(db_connection_config, matches),
Some(("jobs", matches)) => jobs(db_connection_config, matches),
Some(("job", matches)) => job(db_connection_config, config, matches),
+ Some(("log-of", matches)) => log_of(db_connection_config, matches),
Some(("releases", matches)) => releases(db_connection_config, config, matches),
Some((other, _)) => Err(anyhow!("Unknown subcommand: {}", other)),
None => Err(anyhow!("No subcommand")),
@@ -633,6 +635,36 @@ fn job(conn_cfg: DbConnectionConfig, config: &Configuration, matches: &ArgMatche
}
}
+/// Implementation of the subcommand "db log-of"
+fn log_of(conn_cfg: DbConnectionConfig, matches: &ArgMatches) -> Result<()> {
+ let conn = crate::db::establish_connection(conn_cfg)?;
+ let job_uuid = matches
+ .value_of("job_uuid")
+ .map(uuid::Uuid::parse_str)
+ .transpose()?
+ .unwrap();
+ let out = std::io::stdout();
+ let mut lock = out.lock();
+
+ schema::jobs::table
+ .filter(schema::jobs::dsl::uuid.eq(job_uuid))
+ .select(schema::jobs::dsl::log_text)
+ .first::<String>(&conn)
+ .map_err(Error::from)
+ .and_then(crate::log::ParsedLog::build_from)?
+ .iter()
+ .map(|line_item| match line_item {
+ LogItem::Line(s) => Ok(String::from_utf8(s.to_vec())?.normal()),
+ LogItem::Progress(u) => Ok(format!("#BUTIDO:PROGRESS:{}", u).bright_black()),
+ LogItem::CurrentPhase(p) => Ok(format!("#BUTIDO:PHASE:{}", p).bright_black()),
+ LogItem::State(Ok(())) => Ok("#BUTIDO:STATE:OK".to_string().green()),
+ LogItem::State(Err(s)) => Ok(format!("#BUTIDO:STATE:ERR:{}", s).red()),
+ })
+ .and_then_ok(|line| writeln!(lock, "{}", line).map_err(Error::from))
+ .collect::<Result<Vec<()>>>()
+ .map(|_| ())
+}
+
fn releases(conn_cfg: DbConnectionConfig, config: &Configuration, matches: &ArgMatches) -> Result<()> {
let csv = matches.is_present("csv");
let conn = crate::db::establish_connection(conn_cfg)?;