Allow the local-orchestrator to stream agent output into the logs
This is now the third place I have this same exact code. This should be refactored into an otto-exec crate and re-used between `sh`, `otto-agent`, and the local orchestrator
This commit is contained in:
parent
5664cc1aa2
commit
02c34b30fd
|
@ -1618,6 +1618,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"async-std",
|
||||
"log",
|
||||
"os_pipe",
|
||||
"otto-agent",
|
||||
"otto-models",
|
||||
"pretty_env_logger 0.4.0",
|
||||
|
|
|
@ -7,6 +7,7 @@ edition = "2018"
|
|||
[dependencies]
|
||||
async-std = { version = "~1.7", features = ["attributes"]}
|
||||
log = "~0.4.11"
|
||||
os_pipe = "~0.9.2"
|
||||
otto-agent = { path = "../../crates/agent" }
|
||||
otto-models = { path = "../../crates/models" }
|
||||
pretty_env_logger = "~0.4.0"
|
||||
|
|
|
@ -19,6 +19,8 @@ struct RunWorkload {
|
|||
*
|
||||
*/
|
||||
fn run_context(pipeline: &Uuid, ctx: &otto_models::Context) -> std::io::Result<bool> {
|
||||
use os_pipe::pipe;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::process::Command;
|
||||
use tempfile::NamedTempFile;
|
||||
|
@ -39,17 +41,26 @@ fn run_context(pipeline: &Uuid, ctx: &otto_models::Context) -> std::io::Result<b
|
|||
));
|
||||
}
|
||||
|
||||
if let Ok(output) = Command::new("otto-agent").arg(file.path()).output() {
|
||||
use std::io::{stdout, Write};
|
||||
stdout().write(&output.stdout);
|
||||
let mut cmd = Command::new("otto-agent");
|
||||
cmd.arg(file.path());
|
||||
|
||||
return Ok(output.status.success());
|
||||
} else {
|
||||
// TODO
|
||||
error!("Failed to run agent");
|
||||
let (reader, writer) = pipe().unwrap();
|
||||
let writer_clone = writer.try_clone().unwrap();
|
||||
cmd.stdout(writer);
|
||||
cmd.stderr(writer_clone);
|
||||
|
||||
let mut handle = cmd.spawn()?;
|
||||
drop(cmd);
|
||||
|
||||
let bufr = BufReader::new(reader);
|
||||
for line in bufr.lines() {
|
||||
if let Ok(buffer) = line {
|
||||
println!("{}", buffer);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
let status = handle.wait()?;
|
||||
return Ok(status.success());
|
||||
}
|
||||
|
||||
async fn healthcheck(_req: Request<()>) -> tide::Result {
|
||||
|
|
Loading…
Reference in New Issue