mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2025-07-25 19:09:22 +02:00
feat: with loggers
This commit is contained in:
@@ -14,6 +14,8 @@ eyre = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
|
||||
dirs = "4.0.0"
|
||||
flate2 = { version = "1.0.25", features = ["zlib"] }
|
||||
|
@@ -35,7 +35,7 @@ impl InnerCliSession {
|
||||
cli_path: &PathBuf,
|
||||
) -> eyre::Result<(ConnectParams, tokio::process::Child)> {
|
||||
let proc = self.start(config, cli_path)?;
|
||||
let params = self.get_conn(proc).await?;
|
||||
let params = self.get_conn(proc, config).await?;
|
||||
Ok(params)
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ impl InnerCliSession {
|
||||
async fn get_conn(
|
||||
&self,
|
||||
mut proc: tokio::process::Child,
|
||||
config: &Config,
|
||||
) -> eyre::Result<(ConnectParams, tokio::process::Child)> {
|
||||
let stdout = proc
|
||||
.stdout
|
||||
@@ -82,6 +83,7 @@ impl InnerCliSession {
|
||||
|
||||
let (sender, mut receiver) = tokio::sync::mpsc::channel(1);
|
||||
|
||||
let logger = config.logger.as_ref().map(|p| p.clone());
|
||||
tokio::spawn(async move {
|
||||
let mut stdout_bufr = tokio::io::BufReader::new(stdout).lines();
|
||||
while let Ok(Some(line)) = stdout_bufr.next_line().await {
|
||||
@@ -89,14 +91,19 @@ impl InnerCliSession {
|
||||
sender.send(conn).await.unwrap();
|
||||
}
|
||||
|
||||
println!("dagger: {}", line);
|
||||
if let Some(logger) = &logger {
|
||||
logger.stdout(&line).unwrap();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let logger = config.logger.as_ref().map(|p| p.clone());
|
||||
tokio::spawn(async move {
|
||||
let mut stdout_bufr = tokio::io::BufReader::new(stderr).lines();
|
||||
while let Ok(Some(line)) = stdout_bufr.next_line().await {
|
||||
println!("dagger: {}", line);
|
||||
let mut stderr_bufr = tokio::io::BufReader::new(stderr).lines();
|
||||
while let Ok(Some(line)) = stderr_bufr.next_line().await {
|
||||
if let Some(logger) = &logger {
|
||||
logger.stdout(&line).unwrap();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -1,15 +1,18 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::logger::DynLogger;
|
||||
|
||||
pub struct Config {
|
||||
pub workdir_path: Option<PathBuf>,
|
||||
pub config_path: Option<PathBuf>,
|
||||
pub timeout_ms: u64,
|
||||
pub execute_timeout_ms: Option<u64>,
|
||||
pub logger: Option<DynLogger>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self::new(None, None, None, None)
|
||||
Self::new(None, None, None, None, None)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +22,14 @@ impl Config {
|
||||
config_path: Option<PathBuf>,
|
||||
timeout_ms: Option<u64>,
|
||||
execute_timeout_ms: Option<u64>,
|
||||
logger: Option<DynLogger>,
|
||||
) -> Self {
|
||||
Self {
|
||||
workdir_path,
|
||||
config_path,
|
||||
timeout_ms: timeout_ms.unwrap_or(10 * 1000),
|
||||
execute_timeout_ms,
|
||||
logger,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -139,9 +139,10 @@ impl Downloader {
|
||||
if let Ok(entry) = file {
|
||||
let path = entry.path();
|
||||
if path != cli_bin_path {
|
||||
println!(
|
||||
"deleting client: path: {:?} vs cli_bin_path: {:?}",
|
||||
path, cli_bin_path
|
||||
tracing::debug!(
|
||||
path = path.display().to_string(),
|
||||
cli_bin_path = cli_bin_path.display().to_string(),
|
||||
"deleting existing dagger-engine"
|
||||
);
|
||||
std::fs::remove_file(path)?;
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@ impl Engine {
|
||||
&self,
|
||||
cfg: &Config,
|
||||
) -> eyre::Result<(ConnectParams, tokio::process::Child)> {
|
||||
tracing::info!("starting dagger-engine");
|
||||
|
||||
// TODO: Add from existing session as well
|
||||
self.from_cli(cfg).await
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ pub mod connect_params;
|
||||
pub mod downloader;
|
||||
pub mod engine;
|
||||
pub mod introspection;
|
||||
pub mod logger;
|
||||
pub mod schema;
|
||||
pub mod session;
|
||||
|
||||
|
8
crates/dagger-core/src/logger.rs
Normal file
8
crates/dagger-core/src/logger.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
pub trait Logger {
|
||||
fn stdout(&self, output: &str) -> eyre::Result<()>;
|
||||
fn stderr(&self, output: &str) -> eyre::Result<()>;
|
||||
}
|
||||
|
||||
pub type DynLogger = Arc<dyn Logger + Send + Sync>;
|
@@ -2,7 +2,7 @@ use crate::introspection::IntrospectionResponse;
|
||||
use crate::{config::Config, engine::Engine, session::Session};
|
||||
|
||||
pub async fn get_schema() -> eyre::Result<IntrospectionResponse> {
|
||||
let cfg = Config::new(None, None, None, None);
|
||||
let cfg = Config::default();
|
||||
|
||||
//TODO: Implement context for proc
|
||||
let (conn, _proc) = Engine::new().start(&cfg).await?;
|
||||
|
Reference in New Issue
Block a user