From 0ea58b0bafdf137862d113d06b881d9f7b814341 Mon Sep 17 00:00:00 2001 From: Asen Alexandrov Date: Fri, 26 May 2023 08:48:47 +0300 Subject: [PATCH] feat: #103 show number of routes before loading workers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` $$ target/debug/wws . --ignore 'src/**/*' --ignore 'target/**/*' --ignore 'docs/**/*' --ignore 'crates/**/*' | ts May 26 08:49:33 ⚙️ Loading routes from: . May 26 08:49:35 ⏳ Loading workers from 14 routes... May 26 08:50:13 ✅ Workers loaded in 38.128146575s. ... ``` --- crates/router/src/lib.rs | 13 +++++++++++-- src/main.rs | 2 -- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rs index bf6fe449..e60d4a9c 100644 --- a/crates/router/src/lib.rs +++ b/crates/router/src/lib.rs @@ -11,7 +11,8 @@ mod route; use files::Files; use route::{Route, RouteAffinity}; -use std::path::Path; +use std::path::{Path, PathBuf}; +use std::time::{Instant}; use wws_config::Config; /// Contains all registered routes @@ -36,10 +37,18 @@ impl Routes { let files = Files::new(path, runtime_extensions, ignore_patterns); + let mut route_paths: Vec = Vec::new(); for entry in files.walk() { - routes.push(Route::new(path, entry.into_path(), &prefix, config)); + route_paths.push(entry.into_path()); } + println!("⏳ Loading workers from {} routes...", route_paths.len()); + let start = Instant::now(); + for route_path in route_paths { + routes.push(Route::new(path, route_path, &prefix, config)); + } + println!("✅ Workers loaded in {:?}.", start.elapsed()); + Self { routes, prefix } } diff --git a/src/main.rs b/src/main.rs index ff8857d8..964d5499 100644 --- a/src/main.rs +++ b/src/main.rs @@ -107,8 +107,6 @@ async fn main() -> std::io::Result<()> { println!("⚙️ Loading routes from: {}", &args.path.display()); let routes = Routes::new(&args.path, &args.prefix, args.ignore, &config); - - println!("🗺 Detected {} routes:", routes.routes.len()); for route in routes.routes.iter() { println!( " - http://{}:{}{}\n => {}",