diff options
| author | Zeyla Hellyer <[email protected]> | 2017-05-30 07:35:47 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-05-30 20:30:27 -0700 |
| commit | d37461b5b705e0cdf802925c59113898a71676df (patch) | |
| tree | 3789d8d5955673d98bc3ec888f664b834826da4f /src/http | |
| parent | Fix ratelimits causing 429s in certain situations (diff) | |
| download | serenity-d37461b5b705e0cdf802925c59113898a71676df.tar.xz serenity-d37461b5b705e0cdf802925c59113898a71676df.zip | |
Include more info on ratelimiting debugs
In addition to the amount of time sleeping, include the route being
ratelimited.
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/ratelimiting.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/http/ratelimiting.rs b/src/http/ratelimiting.rs index 24cf5e8..9512360 100644 --- a/src/http/ratelimiting.rs +++ b/src/http/ratelimiting.rs @@ -367,7 +367,7 @@ pub fn perform<'a, F>(route: Route, f: F) -> Result<Response> }))).clone(); let mut lock = bucket.lock().unwrap(); - lock.pre_hook(); + lock.pre_hook(&route); let response = super::retry(&f)?; @@ -391,7 +391,7 @@ pub fn perform<'a, F>(route: Route, f: F) -> Result<Response> let _ = GLOBAL.lock().expect("global route lock poisoned"); Ok(if let Some(retry_after) = parse_header(&response.headers, "retry-after")? { - debug!("Ratelimited: {:?}ms", retry_after); + debug!("Ratelimited on route {:?} for {:?}ms", route, retry_after); thread::sleep(Duration::from_millis(retry_after as u64)); true @@ -399,7 +399,7 @@ pub fn perform<'a, F>(route: Route, f: F) -> Result<Response> false }) } else { - lock.post_hook(&response) + lock.post_hook(&response, &route) }; if !redo.unwrap_or(true) { @@ -436,7 +436,7 @@ pub struct RateLimit { impl RateLimit { #[doc(hidden)] - pub fn pre_hook(&mut self) { + pub fn pre_hook(&mut self, route: &Route) { if self.limit == 0 { return; } @@ -455,7 +455,7 @@ impl RateLimit { if self.remaining == 0 { let delay = (diff * 1000) + 500; - debug!("Pre-emptive ratelimit for {:?}ms", delay); + debug!("Pre-emptive ratelimit on route {:?} for {:?}ms", route, delay); thread::sleep(Duration::from_millis(delay)); return; @@ -465,7 +465,7 @@ impl RateLimit { } #[doc(hidden)] - pub fn post_hook(&mut self, response: &Response) -> Result<bool> { + pub fn post_hook(&mut self, response: &Response, route: &Route) -> Result<bool> { if let Some(limit) = parse_header(&response.headers, "x-ratelimit-limit")? { self.limit = limit; } @@ -481,7 +481,7 @@ impl RateLimit { Ok(if response.status != StatusCode::TooManyRequests { false } else if let Some(retry_after) = parse_header(&response.headers, "retry-after")? { - debug!("Ratelimited: {:?}ms", retry_after); + debug!("Ratelimited on route {:?} for {:?}ms", route, retry_after); thread::sleep(Duration::from_millis(retry_after as u64)); true |