Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update tower dependency from 0.4.13 to 0.5.1 #722

Merged
merged 5 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ serde_path_to_error = "0.1.4"
serde_urlencoded = "0.7.1"
snafu = "0.8"
tokio = { version = "1.17.0", default-features = false, features = ["time"], optional = true }
tower = { version = "0.4.13", default-features = false, features = ["util", "buffer"] }
tower = { version = "0.5.1", default-features = false, features = ["util", "buffer"] }
tower-http = { version = "0.6.1", features = ["map-response-body", "trace"] }
tracing = { version = "0.1.37", features = ["log"], optional = true }
url = { version = "2.2.2", features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,8 @@ pub enum AuthState {
}

pub type OctocrabService = Buffer<
BoxService<http::Request<OctoBody>, http::Response<BoxBody<Bytes, Error>>, BoxError>,
http::Request<OctoBody>,
<BoxService<http::Request<OctoBody>, http::Response<BoxBody<Bytes, Error>>, BoxError> as tower::Service<http::Request<OctoBody>>>::Future
>;

/// The GitHub API client.
Expand Down
16 changes: 9 additions & 7 deletions src/service/middleware/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ pub enum RetryConfig {
}

impl<B> Policy<Request<OctoBody>, Response<B>, Error> for RetryConfig {
type Future = futures_util::future::Ready<Self>;
type Future = futures_util::future::Ready<()>;

fn retry(
&self,
_req: &Request<OctoBody>,
result: Result<&Response<B>, &Error>,
&mut self,
_req: &mut Request<OctoBody>,
result: &mut Result<Response<B>, Error>,
) -> Option<Self::Future> {
match self {
RetryConfig::None => None,
RetryConfig::Simple(count) => match result {
Ok(response) => {
if response.status().is_server_error() || response.status() == 429 {
if *count > 0 {
Some(future::ready(RetryConfig::Simple(count - 1)))
*count -= 1;
Some(future::ready(()))
} else {
None
}
Expand All @@ -35,7 +36,8 @@ impl<B> Policy<Request<OctoBody>, Response<B>, Error> for RetryConfig {
}
Err(_) => {
if *count > 0 {
Some(future::ready(RetryConfig::Simple(count - 1)))
*count -= 1;
Some(future::ready(()))
} else {
None
}
Expand All @@ -44,7 +46,7 @@ impl<B> Policy<Request<OctoBody>, Response<B>, Error> for RetryConfig {
}
}

fn clone_request(&self, req: &Request<OctoBody>) -> Option<Request<OctoBody>> {
fn clone_request(&mut self, req: &Request<OctoBody>) -> Option<Request<OctoBody>> {
match self {
RetryConfig::None => None,
_ => {
Expand Down
Loading