0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-10-18 06:22:53 -04:00

Merge pull request #80 from neon-mmd/feat-add-debug-opt

Provide a debug option in the config
This commit is contained in:
zhou fan 2023-05-30 08:11:26 +08:00 committed by GitHub
commit 1976b76d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 12 deletions

16
Cargo.lock generated
View File

@ -125,7 +125,7 @@ dependencies = [
"actix-utils",
"futures-core",
"futures-util",
"mio 0.8.6",
"mio 0.8.7",
"num_cpus",
"socket2",
"tokio 1.28.2",
@ -1510,14 +1510,14 @@ dependencies = [
[[package]]
name = "mio"
version = "0.8.6"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9"
checksum = "eebffdb73fe72e917997fad08bdbf31ac50b0fa91cec93e69a0662e4264d454c"
dependencies = [
"libc",
"log",
"wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys 0.45.0",
"windows-sys 0.48.0",
]
[[package]]
@ -1603,9 +1603,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.17.1"
version = "1.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b"
[[package]]
name = "openssl"
@ -2879,7 +2879,7 @@ dependencies = [
"autocfg 1.1.0",
"bytes 1.4.0",
"libc",
"mio 0.8.6",
"mio 0.8.7",
"num_cpus",
"parking_lot 0.12.1",
"pin-project-lite",
@ -3316,7 +3316,7 @@ dependencies = [
[[package]]
name = "websurfx"
version = "0.10.0"
version = "0.11.0"
dependencies = [
"actix-files",
"actix-web",

View File

@ -1,6 +1,6 @@
[package]
name = "websurfx"
version = "0.10.0"
version = "0.11.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -19,7 +19,7 @@ async fn main() -> std::io::Result<()> {
let config = Config::parse().unwrap();
// Initializing logging middleware with level set to default or info.
if config.logging {
if config.logging || config.debug {
use env_logger::Env;
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
}

View File

@ -26,6 +26,7 @@ pub struct Config {
pub redis_connection_url: String,
pub aggregator: AggreatorConfig,
pub logging: bool,
pub debug: bool,
}
/// Configuration options for the aggregator.
@ -73,6 +74,7 @@ impl Config {
redis_connection_url: globals.get::<_, String>("redis_connection_url")?,
aggregator: aggregator_config,
logging: globals.get::<_, bool>("logging")?,
debug: globals.get::<_, bool>("debug")?,
})
})
}

View File

@ -40,12 +40,13 @@ pub async fn aggregate(
query: &str,
page: u32,
random_delay: bool,
debug: bool,
) -> Result<SearchResults, Box<dyn std::error::Error>> {
let user_agent: String = random_user_agent();
let mut result_map: HashMap<String, RawSearchResult> = HashMap::new();
// Add a random delay before making the request.
if random_delay {
if random_delay || !debug {
let mut rng = rand::thread_rng();
let delay_secs = rng.gen_range(1..10);
std::thread::sleep(Duration::from_secs(delay_secs));

View File

@ -128,7 +128,7 @@ pub async fn search(
}
Err(_) => {
let mut results_json: crate::search_results_handler::aggregation_models::SearchResults =
aggregate(query, page, config.aggregator.random_delay).await?;
aggregate(query, page, config.aggregator.random_delay, config.debug).await?;
results_json.add_style(config.style.clone());
redis_cache
.cache_results(serde_json::to_string(&results_json)?, &page_url)?;

View File

@ -1,5 +1,6 @@
-- ### General ###
logging = true -- an option to enable or disable logs.
debug = false -- an option to enable or disable debug mode.
-- ### Server ###
port = "8080" -- port on which server should be launched