neon_arch commited on
Commit
272fdef
2 Parent(s): f68d9ab a50eb61

Merge branch 'rolling' into improve-results-caching

Browse files
.gitpod.Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM gitpod/workspace-rust
2
+
3
+ RUN sudo install-packages redis-server nodejs npm
.gitpod.yml CHANGED
@@ -1,23 +1,25 @@
1
  ---
2
- image: gitpod/workspace-base
 
 
3
  # Commands that will run on workspace start
4
  tasks:
5
- - name: Setup, Install & Build
6
- before: apt install cargo redis-server nodejs npm -y && cargo test
7
- init: cargo install cargo-watch
8
- command: redis-server --port 8080 & cargo watch -q -w "." -x "run"
9
- # Ports to expose on workspace startup
10
- ports:
11
- - name: Website
12
- description: Website Preview
13
- port: 8080
14
- onOpen: open-preview
15
  # vscode IDE setup
16
  vscode:
17
  extensions:
18
  - vadimcn.vscode-lldb
19
  - cschleiden.vscode-github-actions
20
- - rust-lang.rust
21
  - bungcip.better-toml
22
  - serayuzgur.crates
23
  - usernamehw.errorlens
@@ -26,13 +28,17 @@ vscode:
26
  - stylelint.vscode-stylelint
27
  - dbaeumer.vscode-eslint
28
  - evgeniypeshkov.syntax-highlighter
29
- - redhat.vscode-yaml
30
  - ms-azuretools.vscode-docker
31
  - Catppuccin.catppuccin-vsc
32
  - PKief.material-icon-theme
33
  - oderwat.indent-rainbow
34
  - formulahendry.auto-rename-tag
 
 
 
 
35
  - eamodio.gitlens
 
36
  github:
37
  prebuilds:
38
  master: true
@@ -40,5 +46,5 @@ github:
40
  pullRequests: true
41
  pullRequestsFromForks: true
42
  addCheck: true
43
- addComment: false
44
  addBadge: true
 
1
  ---
2
+ image:
3
+ file: .gitpod.Dockerfile
4
+
5
  # Commands that will run on workspace start
6
  tasks:
7
+ - name: Start Redis Server
8
+ command: redis-server --port 8082
9
+ - name: Run The App
10
+ init: cargo build
11
+ command: PKG_ENV=dev ./target/release/websurfx
12
+ - name: Tests
13
+ command: cargo test
14
+ - name: Clippy Checks
15
+ command: cargo clippy
16
+
17
  # vscode IDE setup
18
  vscode:
19
  extensions:
20
  - vadimcn.vscode-lldb
21
  - cschleiden.vscode-github-actions
22
+ - rust-lang.rust-analyzer
23
  - bungcip.better-toml
24
  - serayuzgur.crates
25
  - usernamehw.errorlens
 
28
  - stylelint.vscode-stylelint
29
  - dbaeumer.vscode-eslint
30
  - evgeniypeshkov.syntax-highlighter
 
31
  - ms-azuretools.vscode-docker
32
  - Catppuccin.catppuccin-vsc
33
  - PKief.material-icon-theme
34
  - oderwat.indent-rainbow
35
  - formulahendry.auto-rename-tag
36
+ - swellaby.vscode-rust-test-adapter
37
+ - belfz.search-crates-io
38
+ - hbenl.test-adapter-converter
39
+ - hbenl.vscode-test-explorer
40
  - eamodio.gitlens
41
+
42
  github:
43
  prebuilds:
44
  master: true
 
46
  pullRequests: true
47
  pullRequestsFromForks: true
48
  addCheck: true
49
+ addComment: false
50
  addBadge: true
docs/configuration.md CHANGED
@@ -23,6 +23,7 @@ Some of the configuration options provided in the file are stated below. These a
23
 
24
  - **logging:** An option to enable or disable logs.
25
  - **debug:** An option to enable or disable debug mode.
 
26
 
27
  ## Server
28
 
 
23
 
24
  - **logging:** An option to enable or disable logs.
25
  - **debug:** An option to enable or disable debug mode.
26
+ - **threads:** The amount of threads that the app will use to run (the value should be greater than 0).
27
 
28
  ## Server
29
 
docs/installation.md CHANGED
@@ -79,6 +79,7 @@ After that edit the config.lua file located under `websurfx` directory. In the c
79
  -- ### General ###
80
  logging = true -- an option to enable or disable logs.
81
  debug = false -- an option to enable or disable debug mode.
 
82
 
83
  -- ### Server ###
84
  port = "8080" -- port on which server should be launched
 
79
  -- ### General ###
80
  logging = true -- an option to enable or disable logs.
81
  debug = false -- an option to enable or disable debug mode.
82
+ threads = 10 -- the amount of threads that the app will use to run (the value should be greater than 0).
83
 
84
  -- ### Server ###
85
  port = "8080" -- port on which server should be launched
src/bin/websurfx.rs CHANGED
@@ -24,8 +24,8 @@ async fn main() -> std::io::Result<()> {
24
  );
25
  log::info!(
26
  "Open http://{}:{}/ in your browser",
 
27
  config.port,
28
- config.binding_ip
29
  );
30
 
31
  let listener = TcpListener::bind((config.binding_ip.clone(), config.port))?;
 
24
  );
25
  log::info!(
26
  "Open http://{}:{}/ in your browser",
27
+ config.binding_ip,
28
  config.port,
 
29
  );
30
 
31
  let listener = TcpListener::bind((config.binding_ip.clone(), config.port))?;
src/config/parser.rs CHANGED
@@ -4,7 +4,7 @@
4
  use super::parser_models::Style;
5
  use log::LevelFilter;
6
  use rlua::Lua;
7
- use std::{collections::HashMap, format, fs, io::Write, path::Path, thread::available_parallelism};
8
 
9
  // ------- Constants --------
10
  static COMMON_DIRECTORY_NAME: &str = "websurfx";
@@ -79,26 +79,26 @@ impl Config {
79
 
80
  // Check whether logging has not been initialized before.
81
  if logging_initialized {
82
- // Initializing logging middleware with level set to default or info.
83
- let mut log_level: LevelFilter = LevelFilter::Off;
84
- if logging && debug == false {
85
- log_level = LevelFilter::Info;
86
- } else if debug {
87
- log_level = LevelFilter::Trace;
88
- };
89
- env_logger::Builder::new().filter(None, log_level).init();
 
 
 
 
 
 
90
  }
91
 
92
  let threads: u8 = if parsed_threads == 0 {
93
- let total_num_of_threads:usize = available_parallelism()?.get() /2;
94
- if debug || logging {
95
- log::error!("Config Error: The value of `threads` option should be a non zero positive integer");
96
- log::info!("Falling back to using {} threads", total_num_of_threads)
97
- } else {
98
- std::io::stdout()
99
- .lock()
100
- .write_all(&format!("Config Error: The value of `threads` option should be a non zero positive integer\nFalling back to using {} threads\n", total_num_of_threads).into_bytes())?;
101
- };
102
  total_num_of_threads as u8
103
  } else {
104
  parsed_threads
 
4
  use super::parser_models::Style;
5
  use log::LevelFilter;
6
  use rlua::Lua;
7
+ use std::{collections::HashMap, format, fs, path::Path, thread::available_parallelism};
8
 
9
  // ------- Constants --------
10
  static COMMON_DIRECTORY_NAME: &str = "websurfx";
 
79
 
80
  // Check whether logging has not been initialized before.
81
  if logging_initialized {
82
+ if let Ok(pkg_env_var) = std::env::var("PKG_ENV"){
83
+ if pkg_env_var.to_lowercase() == "dev" {
84
+ env_logger::Builder::new().filter(None, LevelFilter::Trace).init();
85
+ }
86
+ } else {
87
+ // Initializing logging middleware with level set to default or info.
88
+ let mut log_level: LevelFilter = LevelFilter::Error;
89
+ if logging && debug == false {
90
+ log_level = LevelFilter::Info;
91
+ } else if debug {
92
+ log_level = LevelFilter::Debug;
93
+ };
94
+ env_logger::Builder::new().filter(None, log_level).init();
95
+ }
96
  }
97
 
98
  let threads: u8 = if parsed_threads == 0 {
99
+ let total_num_of_threads: usize = available_parallelism()?.get() / 2;
100
+ log::error!("Config Error: The value of `threads` option should be a non zero positive integer");
101
+ log::error!("Falling back to using {} threads", total_num_of_threads);
 
 
 
 
 
 
102
  total_num_of_threads as u8
103
  } else {
104
  parsed_threads
src/results/aggregator.rs CHANGED
@@ -144,6 +144,7 @@ pub async fn aggregate(
144
  initial = false
145
  }
146
  Err(error_type) => {
 
147
  engine_errors_info.push(EngineErrorInfo::new(
148
  error_type.downcast_ref::<EngineError>().unwrap(),
149
  upstream_search_engines[counter].clone(),
@@ -172,6 +173,7 @@ pub async fn aggregate(
172
  counter += 1
173
  }
174
  Err(error_type) => {
 
175
  engine_errors_info.push(EngineErrorInfo::new(
176
  error_type.downcast_ref::<EngineError>().unwrap(),
177
  upstream_search_engines[counter].clone(),
 
144
  initial = false
145
  }
146
  Err(error_type) => {
147
+ log::error!("Engine Error: {:?}", error_type);
148
  engine_errors_info.push(EngineErrorInfo::new(
149
  error_type.downcast_ref::<EngineError>().unwrap(),
150
  upstream_search_engines[counter].clone(),
 
173
  counter += 1
174
  }
175
  Err(error_type) => {
176
+ log::error!("Engine Error: {:?}", error_type);
177
  engine_errors_info.push(EngineErrorInfo::new(
178
  error_type.downcast_ref::<EngineError>().unwrap(),
179
  upstream_search_engines[counter].clone(),