Skip to content

Commit

Permalink
🔧 fix: fix port occupancy issue (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Liquidwe authored Dec 16, 2024
1 parent f2fd106 commit 4b37715
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 7 deletions.
35 changes: 35 additions & 0 deletions gui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ lazy_static = "1.4.0"
base64 = "0.22.1"
aes-gcm = "0.10.3"
sysinfo = "0.33.0"
rand = "0.8.5"
rand = "0.8.5"
log = "0.4"
simplelog = "0.12"
time = { version = "0.3", features = ["macros"] }
3 changes: 2 additions & 1 deletion gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pub mod config;
pub mod app;
pub mod ui;
pub mod prerun;
pub mod tasks;
pub mod tasks;
pub mod logger;
50 changes: 50 additions & 0 deletions gui/src/logger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::fs::File;
use std::path::PathBuf;
use simplelog::*;
use chrono::Local;
use std::io;
use time::macros::format_description;

pub struct Logger;

impl Logger {
pub fn init() -> io::Result<()> {
let home_dir = dirs::home_dir()
.ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "Home directory not found"))?;

let log_dir = home_dir.join(".manuscript").join("logs");
std::fs::create_dir_all(&log_dir)?;

let log_file_name = format!("manuscript_{}.log", Local::now().format("%Y-%m-%d"));
let log_file_path = log_dir.join(log_file_name);

println!("log_file_path: {}", log_file_path.to_string_lossy());

let config = ConfigBuilder::new()
.set_time_format_custom(format_description!("[year]-[month]-[day] [hour]:[minute]:[second].[subsecond digits:3]"))
.set_thread_level(LevelFilter::Info)
.set_target_level(LevelFilter::Error)
.set_location_level(LevelFilter::Debug)
.build();

CombinedLogger::init(vec![
WriteLogger::new(
LevelFilter::Info,
config.clone(),
File::create(log_file_path)?
),
]).map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;

Ok(())
}

pub fn get_log_path() -> io::Result<PathBuf> {
let home_dir = dirs::home_dir()
.ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "Home directory not found"))?;

let log_dir = home_dir.join(".manuscript").join("logs");
let log_file_name = format!("manuscript_{}.log", Local::now().format("%Y-%m-%d"));

Ok(log_dir.join(log_file_name))
}
}
6 changes: 4 additions & 2 deletions gui/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use manuscript_gui::app::App;
use manuscript_gui::logger::Logger;

#[tokio::main]
async fn main() -> std::io::Result<()> {
env_logger::init();

if let Err(e) = Logger::init() {
eprintln!("Failed to initialize logger: {}", e);
}
let mut terminal = ratatui::init();
let mut app = App::new().await;
let app_result = app.run(&mut terminal);
Expand Down
9 changes: 6 additions & 3 deletions gui/src/tasks/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,12 @@ impl JobManager {
name: yaml["name"].as_str().unwrap_or("demo").to_string(),
spec_version: yaml["specVersion"].as_str().unwrap_or("v1.0.0").to_string(),
parallelism: yaml["parallelism"].as_u64().unwrap_or(1),
db_port: yaml["port"].as_u64().unwrap_or(15432) as u16,
graphql_port: yaml["graphqlPort"].as_u64().unwrap_or(19080) as u16,
job_port: yaml["port"].as_u64().unwrap_or(18080) as u16,
db_port: self.get_available_port(15432, 15439)
.unwrap_or(15432),
graphql_port: self.get_available_port(19080, 19090)
.unwrap_or(19080),
job_port: self.get_available_port(18080, 18090)
.unwrap_or(18080),
source: SourceConfig {
name: source["name"].as_str().unwrap_or("").to_string(),
dataset_type: source["type"].as_str().unwrap_or("dataset").to_string(),
Expand Down

0 comments on commit 4b37715

Please sign in to comment.