Moving retry_limit to settings

fix_retry
Dessalines 2021-12-03 22:08:07 -05:00
parent 31cd4edc2c
commit e2709f6967
5 changed files with 9 additions and 8 deletions

View File

@ -111,4 +111,6 @@
slur_filter: "(\bThis\b)|(\bis\b)|(\bsample\b)" slur_filter: "(\bThis\b)|(\bis\b)|(\bsample\b)"
# Maximum length of local community and user names # Maximum length of local community and user names
actor_name_max_length: 20 actor_name_max_length: 20
# Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object fetch through the search).
http_fetch_retry_limit: 25
} }

View File

@ -7,7 +7,7 @@ use lemmy_apub_lib::{
}; };
use lemmy_db_schema::newtypes::DbUrl; use lemmy_db_schema::newtypes::DbUrl;
use lemmy_utils::{ use lemmy_utils::{
request::{retry, RecvError, RETRY_LIMIT}, request::{retry, RecvError},
LemmyError, LemmyError,
}; };
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
@ -82,7 +82,7 @@ where
debug!("Fetching webfinger url: {}", &fetch_url); debug!("Fetching webfinger url: {}", &fetch_url);
*request_counter += 1; *request_counter += 1;
if *request_counter > RETRY_LIMIT { if *request_counter > context.settings().http_fetch_retry_limit {
return Err(LemmyError::from(anyhow!("Request retry limit reached"))); return Err(LemmyError::from(anyhow!("Request retry limit reached")));
} }

View File

@ -3,7 +3,7 @@ use activitystreams::chrono::{Duration as ChronoDuration, NaiveDateTime, Utc};
use anyhow::anyhow; use anyhow::anyhow;
use diesel::NotFound; use diesel::NotFound;
use lemmy_utils::{ use lemmy_utils::{
request::{build_user_agent, retry, RETRY_LIMIT}, request::{build_user_agent, retry},
settings::structs::Settings, settings::structs::Settings,
LemmyError, LemmyError,
}; };
@ -115,7 +115,7 @@ where
info!("Fetching remote object {}", self.to_string()); info!("Fetching remote object {}", self.to_string());
*request_counter += 1; *request_counter += 1;
if *request_counter > RETRY_LIMIT { if *request_counter > Settings::get().http_fetch_retry_limit {
return Err(LemmyError::from(anyhow!("Request retry limit reached"))); return Err(LemmyError::from(anyhow!("Request retry limit reached")));
} }

View File

@ -17,10 +17,6 @@ struct SendError(pub String);
#[error("Error receiving response, {0}")] #[error("Error receiving response, {0}")]
pub struct RecvError(pub String); pub struct RecvError(pub String);
/// Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object
/// fetch through the search). This should be configurable.
pub static RETRY_LIMIT: i32 = 25;
pub async fn retry<F, Fut, T>(f: F) -> Result<T, reqwest::Error> pub async fn retry<F, Fut, T>(f: F) -> Result<T, reqwest::Error>
where where
F: Fn() -> Fut, F: Fn() -> Fut,

View File

@ -46,6 +46,9 @@ pub struct Settings {
/// Maximum length of local community and user names /// Maximum length of local community and user names
#[default(20)] #[default(20)]
pub actor_name_max_length: usize, pub actor_name_max_length: usize,
/// Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object fetch through the search).
#[default(25)]
pub http_fetch_retry_limit: i32,
} }
#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)] #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]