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:
pvichivanives 2024-05-31 18:02:26 -07:00 committed by GitHub
parent 3ae02fcd8b
commit 2927624652
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 6 deletions

View file

@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added `with_retry_log_level` to `RetryTransientMiddleware`
### Changed
- Upgraded `retry-policies` to `0.4.0`.
## [0.5.0] - 2024-04-10
### Breaking changes

View file

@ -18,7 +18,7 @@ chrono = { version = "0.4.19", features = ["clock"], default-features = false }
futures = "0.3.0"
http = "1.0"
reqwest = { version = "0.12.0", default-features = false }
retry-policies = "0.3.0"
retry-policies = "0.4"
tracing = "0.1.26"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

View file

@ -1,8 +1,9 @@
//! `RetryTransientMiddleware` implements retrying requests on transient errors.
use std::time::{Duration, SystemTime};
use crate::retryable_strategy::RetryableStrategy;
use crate::{retryable::Retryable, retryable_strategy::DefaultRetryableStrategy};
use anyhow::anyhow;
use chrono::Utc;
use http::Extensions;
use reqwest::{Request, Response};
use reqwest_middleware::{Error, Middleware, Next, Result};
@ -136,7 +137,7 @@ where
ext: &'a mut Extensions,
) -> Result<Response> {
let mut n_past_retries = 0;
let start_time = Utc::now();
let start_time = SystemTime::now();
loop {
// 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`,
@ -158,9 +159,9 @@ where
// we can safely try to retry the request.
let retry_decision = self.retry_policy.should_retry(start_time, n_past_retries);
if let retry_policies::RetryDecision::Retry { execute_after } = retry_decision {
let duration = (execute_after - Utc::now())
.to_std()
.map_err(Error::middleware)?;
let duration = execute_after
.duration_since(SystemTime::now())
.unwrap_or_else(|_| Duration::default());
// Sleep the requested amount before we try again.
log_retry!(
self.retry_log_level,