mirror of
https://github.com/TrueLayer/reqwest-middleware.git
synced 2024-12-26 19:06:31 +00:00
Bump retry-policies to 0.4 (#155)
* bump reqwest to 0.4 * Update reqwest-retry/src/middleware.rs Co-authored-by: Chris Beck <5683852+cbeck88@users.noreply.github.com> * fix unwrap issue --------- Co-authored-by: Chris Beck <5683852+cbeck88@users.noreply.github.com> Co-authored-by: Ethan Brierley <ethanboxx@gmail.com>
This commit is contained in:
parent
3ae02fcd8b
commit
2927624652
3 changed files with 10 additions and 6 deletions
|
@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Added
|
### Added
|
||||||
- Added `with_retry_log_level` to `RetryTransientMiddleware`
|
- Added `with_retry_log_level` to `RetryTransientMiddleware`
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Upgraded `retry-policies` to `0.4.0`.
|
||||||
|
|
||||||
## [0.5.0] - 2024-04-10
|
## [0.5.0] - 2024-04-10
|
||||||
|
|
||||||
### Breaking changes
|
### Breaking changes
|
||||||
|
|
|
@ -18,7 +18,7 @@ chrono = { version = "0.4.19", features = ["clock"], default-features = false }
|
||||||
futures = "0.3.0"
|
futures = "0.3.0"
|
||||||
http = "1.0"
|
http = "1.0"
|
||||||
reqwest = { version = "0.12.0", default-features = false }
|
reqwest = { version = "0.12.0", default-features = false }
|
||||||
retry-policies = "0.3.0"
|
retry-policies = "0.4"
|
||||||
tracing = "0.1.26"
|
tracing = "0.1.26"
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
//! `RetryTransientMiddleware` implements retrying requests on transient errors.
|
//! `RetryTransientMiddleware` implements retrying requests on transient errors.
|
||||||
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
use crate::retryable_strategy::RetryableStrategy;
|
use crate::retryable_strategy::RetryableStrategy;
|
||||||
use crate::{retryable::Retryable, retryable_strategy::DefaultRetryableStrategy};
|
use crate::{retryable::Retryable, retryable_strategy::DefaultRetryableStrategy};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use chrono::Utc;
|
|
||||||
use http::Extensions;
|
use http::Extensions;
|
||||||
use reqwest::{Request, Response};
|
use reqwest::{Request, Response};
|
||||||
use reqwest_middleware::{Error, Middleware, Next, Result};
|
use reqwest_middleware::{Error, Middleware, Next, Result};
|
||||||
|
@ -136,7 +137,7 @@ where
|
||||||
ext: &'a mut Extensions,
|
ext: &'a mut Extensions,
|
||||||
) -> Result<Response> {
|
) -> Result<Response> {
|
||||||
let mut n_past_retries = 0;
|
let mut n_past_retries = 0;
|
||||||
let start_time = Utc::now();
|
let start_time = SystemTime::now();
|
||||||
loop {
|
loop {
|
||||||
// Cloning the request object before-the-fact is not ideal..
|
// Cloning the request object before-the-fact is not ideal..
|
||||||
// However, if the body of the request is not static, e.g of type `Bytes`,
|
// However, if the body of the request is not static, e.g of type `Bytes`,
|
||||||
|
@ -158,9 +159,9 @@ where
|
||||||
// we can safely try to retry the request.
|
// we can safely try to retry the request.
|
||||||
let retry_decision = self.retry_policy.should_retry(start_time, n_past_retries);
|
let retry_decision = self.retry_policy.should_retry(start_time, n_past_retries);
|
||||||
if let retry_policies::RetryDecision::Retry { execute_after } = retry_decision {
|
if let retry_policies::RetryDecision::Retry { execute_after } = retry_decision {
|
||||||
let duration = (execute_after - Utc::now())
|
let duration = execute_after
|
||||||
.to_std()
|
.duration_since(SystemTime::now())
|
||||||
.map_err(Error::middleware)?;
|
.unwrap_or_else(|_| Duration::default());
|
||||||
// Sleep the requested amount before we try again.
|
// Sleep the requested amount before we try again.
|
||||||
log_retry!(
|
log_retry!(
|
||||||
self.retry_log_level,
|
self.retry_log_level,
|
||||||
|
|
Loading…
Reference in a new issue