Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Add connect timeout to internal client #276

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "safe-client-gateway"
version = "1.8.1"
version = "1.8.2"
authors = ["jpalvarezl <jose.alvarez@gnosis.io>"]
edition = "2018"

Expand Down
13 changes: 12 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ fn usize_with_default(key: &str, default: usize) -> usize {
}
}

fn u64_with_default(key: &str, default: u64) -> u64 {
match env::var(key) {
Ok(value) => value.parse().unwrap(),
Err(_) => default,
}
}

pub fn info_cache_duration() -> usize {
usize_with_default("INFO_CACHE_DURATION", 60 * 15)
}
Expand All @@ -36,7 +43,11 @@ pub fn about_cache_duration() -> usize {
}

pub fn safe_app_manifest_cache() -> usize {
usize_with_default("SAFE_APP_MANIFEST_CACHE_DURATION", 60 * 60 * 24 * 7) // is a week good?
usize_with_default("SAFE_APP_MANIFEST_CACHE_DURATION", 60 * 60 * 24 * 7)
}

pub fn internal_client_connect_timeout() -> u64 {
u64_with_default("INTERNAL_CLIENT_CONNECT_TIMEOUT", 1000)
}

pub fn build_number() -> Option<String> {
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ use dotenv::dotenv;
use routes::active_routes;
use utils::cache::ServiceCache;
use utils::cors::CORS;
use std::time::Duration;

fn main() {
dotenv().ok();
env_logger::init();

let client = reqwest::blocking::Client::builder()
.connect_timeout(Duration::from_millis(config::internal_client_connect_timeout()))
.build()
.unwrap();

rocket::ignite()
.mount("/", active_routes())
.manage(reqwest::blocking::Client::new())
.manage(client)
.attach(monitoring::performance::PerformanceMonitor())
.attach(CORS())
.attach(ServiceCache::fairing())
Expand Down