Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
feat: add timeout for calls to ADM service (#140)
Browse files Browse the repository at this point in the history
* feat: add timeout for calls to ADM service

* Uses setting `adm_timeout`, and defaults to 5 seconds

I suspect that we probably may have different timeouts for various
partners. There is no timeout specified for a default reqwest builder.

Closes #139
  • Loading branch information
jrconlin authored Jun 8, 2021
1 parent 786fe72 commit 4837bb5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/adm/tiles.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt::Debug, fs::File, io::BufReader, path::Path};
use std::{fmt::Debug, fs::File, io::BufReader, path::Path, time::Duration};

use actix_http::http::header::{HeaderMap, HeaderValue};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -159,6 +159,7 @@ pub async fn get_tiles(
// TODO: Add timeout
reqwest_client
.get(adm_url)
.timeout(Duration::from_secs(settings.adm_timeout))
.send()
.await
.map_err(|e| {
Expand Down
3 changes: 3 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub struct Settings {
pub adm_max_tiles: u8,
/// number of tiles to query from ADM (default: 10)
pub adm_query_tile_count: u8,
/// Timeout requests to the ADM server after this many seconds (default: 5)
pub adm_timeout: u64,
/// Expire tiles after this many seconds (15 * 60s)
pub tiles_ttl: u32,
/// ADM tile settings (either as JSON or a path to a JSON file)
Expand Down Expand Up @@ -101,6 +103,7 @@ impl Default for Settings {
adm_country_ip_map: DEFAULT_ADM_COUNTRY_IP_MAP.to_owned(),
adm_max_tiles: 2,
adm_query_tile_count: 10,
adm_timeout: 5,
tiles_ttl: 15 * 60,
adm_settings: "".to_owned(),
maxminddb_loc: None,
Expand Down

0 comments on commit 4837bb5

Please sign in to comment.