mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-22 05:58:21 -05:00
Merge pull request #80 from neon-mmd/feat-add-debug-opt
Provide a debug option in the config
This commit is contained in:
commit
1976b76d3c
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -125,7 +125,7 @@ dependencies = [
|
|||||||
"actix-utils",
|
"actix-utils",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"mio 0.8.6",
|
"mio 0.8.7",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"socket2",
|
"socket2",
|
||||||
"tokio 1.28.2",
|
"tokio 1.28.2",
|
||||||
@ -1510,14 +1510,14 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mio"
|
name = "mio"
|
||||||
version = "0.8.6"
|
version = "0.8.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9"
|
checksum = "eebffdb73fe72e917997fad08bdbf31ac50b0fa91cec93e69a0662e4264d454c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||||
"windows-sys 0.45.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1603,9 +1603,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.17.1"
|
version = "1.17.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl"
|
name = "openssl"
|
||||||
@ -2879,7 +2879,7 @@ dependencies = [
|
|||||||
"autocfg 1.1.0",
|
"autocfg 1.1.0",
|
||||||
"bytes 1.4.0",
|
"bytes 1.4.0",
|
||||||
"libc",
|
"libc",
|
||||||
"mio 0.8.6",
|
"mio 0.8.7",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot 0.12.1",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
@ -3316,7 +3316,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "websurfx"
|
name = "websurfx"
|
||||||
version = "0.10.0"
|
version = "0.11.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-files",
|
"actix-files",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "websurfx"
|
name = "websurfx"
|
||||||
version = "0.10.0"
|
version = "0.11.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -19,7 +19,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
let config = Config::parse().unwrap();
|
let config = Config::parse().unwrap();
|
||||||
|
|
||||||
// Initializing logging middleware with level set to default or info.
|
// Initializing logging middleware with level set to default or info.
|
||||||
if config.logging {
|
if config.logging || config.debug {
|
||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ pub struct Config {
|
|||||||
pub redis_connection_url: String,
|
pub redis_connection_url: String,
|
||||||
pub aggregator: AggreatorConfig,
|
pub aggregator: AggreatorConfig,
|
||||||
pub logging: bool,
|
pub logging: bool,
|
||||||
|
pub debug: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configuration options for the aggregator.
|
/// Configuration options for the aggregator.
|
||||||
@ -73,6 +74,7 @@ impl Config {
|
|||||||
redis_connection_url: globals.get::<_, String>("redis_connection_url")?,
|
redis_connection_url: globals.get::<_, String>("redis_connection_url")?,
|
||||||
aggregator: aggregator_config,
|
aggregator: aggregator_config,
|
||||||
logging: globals.get::<_, bool>("logging")?,
|
logging: globals.get::<_, bool>("logging")?,
|
||||||
|
debug: globals.get::<_, bool>("debug")?,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -40,12 +40,13 @@ pub async fn aggregate(
|
|||||||
query: &str,
|
query: &str,
|
||||||
page: u32,
|
page: u32,
|
||||||
random_delay: bool,
|
random_delay: bool,
|
||||||
|
debug: bool,
|
||||||
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
||||||
let user_agent: String = random_user_agent();
|
let user_agent: String = random_user_agent();
|
||||||
let mut result_map: HashMap<String, RawSearchResult> = HashMap::new();
|
let mut result_map: HashMap<String, RawSearchResult> = HashMap::new();
|
||||||
|
|
||||||
// Add a random delay before making the request.
|
// Add a random delay before making the request.
|
||||||
if random_delay {
|
if random_delay || !debug {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let delay_secs = rng.gen_range(1..10);
|
let delay_secs = rng.gen_range(1..10);
|
||||||
std::thread::sleep(Duration::from_secs(delay_secs));
|
std::thread::sleep(Duration::from_secs(delay_secs));
|
||||||
|
@ -128,7 +128,7 @@ pub async fn search(
|
|||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let mut results_json: crate::search_results_handler::aggregation_models::SearchResults =
|
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());
|
results_json.add_style(config.style.clone());
|
||||||
redis_cache
|
redis_cache
|
||||||
.cache_results(serde_json::to_string(&results_json)?, &page_url)?;
|
.cache_results(serde_json::to_string(&results_json)?, &page_url)?;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
-- ### General ###
|
-- ### General ###
|
||||||
logging = true -- an option to enable or disable logs.
|
logging = true -- an option to enable or disable logs.
|
||||||
|
debug = false -- an option to enable or disable debug mode.
|
||||||
|
|
||||||
-- ### Server ###
|
-- ### Server ###
|
||||||
port = "8080" -- port on which server should be launched
|
port = "8080" -- port on which server should be launched
|
||||||
|
Loading…
Reference in New Issue
Block a user