From 2927624652097b687f2970fba2cf454d04b1eb1a Mon Sep 17 00:00:00 2001 From: pvichivanives <141073394+pvichivanives@users.noreply.github.com> Date: Fri, 31 May 2024 18:02:26 -0700 Subject: [PATCH] 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 --- reqwest-retry/CHANGELOG.md | 3 +++ reqwest-retry/Cargo.toml | 2 +- reqwest-retry/src/middleware.rs | 11 ++++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/reqwest-retry/CHANGELOG.md b/reqwest-retry/CHANGELOG.md index 90cd55a..1190cbe 100644 --- a/reqwest-retry/CHANGELOG.md +++ b/reqwest-retry/CHANGELOG.md @@ -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 diff --git a/reqwest-retry/Cargo.toml b/reqwest-retry/Cargo.toml index 1a52f32..9dd75d7 100644 --- a/reqwest-retry/Cargo.toml +++ b/reqwest-retry/Cargo.toml @@ -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] diff --git a/reqwest-retry/src/middleware.rs b/reqwest-retry/src/middleware.rs index 70707b8..cd7cda3 100644 --- a/reqwest-retry/src/middleware.rs +++ b/reqwest-retry/src/middleware.rs @@ -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 { 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,