Skip to content

Commit

Permalink
Bump retry-policies to 0.4 (#155)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Jun 1, 2024
1 parent 3ae02fc commit 2927624
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions reqwest-retry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion reqwest-retry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 6 additions & 5 deletions reqwest-retry/src/middleware.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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`,
Expand All @@ -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,
Expand Down

0 comments on commit 2927624

Please sign in to comment.