Interpret the nix logs.
This commit is contained in:
2
src/command/feed_logs/mod.rs
Normal file
2
src/command/feed_logs/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
mod runner;
|
||||
pub(crate) use runner::feed_logs;
|
||||
55
src/command/feed_logs/runner.rs
Normal file
55
src/command/feed_logs/runner.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use tokio::fs::File;
|
||||
use tokio::io::AsyncBufReadExt;
|
||||
use tokio::io::BufReader;
|
||||
use tokio::io::Lines;
|
||||
|
||||
use crate::cli::parameters::FeedLogArgs;
|
||||
|
||||
use crate::Result;
|
||||
use crate::database::db_handle::DbHandle;
|
||||
use crate::nix_util::NixOutputStream;
|
||||
use crate::nix_util::OutputLine;
|
||||
use crate::nix_util::OutputLineStream;
|
||||
use crate::nix_util::RunningBuild;
|
||||
|
||||
pub(crate) async fn feed_logs(args: FeedLogArgs) -> Result<()> {
|
||||
let db_handle = DbHandle::new::<String>(None).await?;
|
||||
let mut running_build = RunningBuild::new(&db_handle)?;
|
||||
let file_stream = FileStream::new(args.input).await?;
|
||||
let mut nix_output_stream = NixOutputStream::new(file_stream);
|
||||
while let Some(message) = nix_output_stream.next().await? {
|
||||
running_build.handle_message(message)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct FileStream {
|
||||
lines: Lines<BufReader<File>>,
|
||||
file_path: PathBuf,
|
||||
}
|
||||
|
||||
impl FileStream {
|
||||
pub(crate) async fn new<P: AsRef<Path>>(path: P) -> Result<Self> {
|
||||
let f = File::open(&path).await?;
|
||||
let foo = BufReader::new(f).lines();
|
||||
Ok(FileStream {
|
||||
lines: foo,
|
||||
file_path: path.as_ref().to_owned(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl OutputLineStream for FileStream {
|
||||
async fn next_line(&mut self) -> Result<OutputLine> {
|
||||
let line = self.lines.next_line().await?;
|
||||
if let Some(l) = line {
|
||||
Ok(OutputLine::Stdout(l))
|
||||
} else {
|
||||
Ok(OutputLine::Done)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
pub(crate) mod build;
|
||||
pub(crate) mod daemon;
|
||||
pub(crate) mod feed_logs;
|
||||
|
||||
Reference in New Issue
Block a user