Skip to content

Commit

Permalink
Bump Tower version to 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
NickAcPT committed Sep 15, 2024
1 parent e621000 commit e621000
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
39 changes: 27 additions & 12 deletions nmsr-aas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ nmsr-rendering-blockbench-model-generator-experiment = { path = "../utils/nmsr-r
ears-rs = { workspace = true }

anyhow = { workspace = true }
axum = { version = "0.7", features = [
"macros",
"tokio"
] }
axum-extra = { version = "0.9", features = [
"multipart",
] }
axum = { version = "0.7", features = ["macros", "tokio"] }
axum-extra = { version = "0.9", features = ["multipart"] }
http-body-util = "0.1"

# async-trait - Async trait support because Rust is bad at async
Expand All @@ -45,12 +40,25 @@ base64 = "0.22"

# Hyper - HTTP client
hyper = { version = "1.4", features = ["client"] }
hyper-util = { version = "0.1", features = ["client", "client-legacy", "http1", "http2", "server-auto", "tokio"] }
hyper-util = { version = "0.1", features = [
"client",
"client-legacy",
"http1",
"http2",
"server-auto",
"tokio",
] }
hyper-tls = "0.6"
url = "2.5"

# Tokio - Async runtime
tokio = { workspace = true, features = ["macros", "fs", "sync", "signal", "rt-multi-thread"] }
tokio = { workspace = true, features = [
"macros",
"fs",
"sync",
"signal",
"rt-multi-thread",
] }

# async-scoped - Scoped async tasks
async-scoped = { version = "0.9", features = ["use-tokio"] }
Expand Down Expand Up @@ -83,8 +91,15 @@ thiserror = { workspace = true }
derive_more = { workspace = true }

# Tower - Service framework
tower = { version = "0.4", features = ["limit", "timeout", "retry"] }
tower-http = { version = "0.5", features = ["full"] }
tower = { version = "0.5", features = ["buffer", "limit", "timeout", "retry"] }
tower-http = { version = "0.5", features = [
"set-header",
"trace",
"request-id",
"cors",
"normalize-path",
"fs",
] }
http = "1.1"

# symlink - Symbolic link library (because Rust's standard library doesn't handle that properly for us)
Expand Down Expand Up @@ -112,4 +127,4 @@ default = []
ears = [
"nmsr-rendering/ears",
"nmsr-rendering-blockbench-model-generator-experiment/ears",
]
]
13 changes: 6 additions & 7 deletions nmsr-aas/src/utils/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub(crate) type NmsrTraceLayer = Trace<
>;

pub struct NmsrHttpClient {
inner: Buffer<RateLimit<Retry<MojankRetryPolicy, Timeout<NmsrTraceLayer>>>, Request<SyncBody>>,
inner: Buffer<Request<SyncBody>, <RateLimit<Retry<MojankRetryPolicy, Timeout<NmsrTraceLayer>>> as Service<Request<SyncBody>>>::Future>,
}

impl NmsrHttpClient {
Expand Down Expand Up @@ -150,24 +150,23 @@ impl MojankRetryPolicy {
}

impl<P, Res> Policy<Request<SyncBody>, Res, P> for MojankRetryPolicy {
type Future = Ready<MojankRetryPolicy>;
type Future = Ready<()>;

fn retry(&self, _req: &Request<SyncBody>, result: Result<&Res, &P>) -> Option<Self::Future> {
fn retry(&mut self, _req: &mut Request<SyncBody>, result: &mut Result<Res, P>) -> Option<Self::Future> {
match result {
Ok(_) => None,
Err(_) => {
if self.attempts > 0 {
Some(ready(Self {
attempts: self.attempts - 1,
}))
self.attempts -= 1;
Some(ready(()))
} else {
None
}
}
}
}

fn clone_request(&self, req: &Request<SyncBody>) -> Option<Request<SyncBody>> {
fn clone_request(&mut self, req: &Request<SyncBody>) -> Option<Request<SyncBody>> {
let method = req.method().clone();
let uri = req.uri().clone();

Expand Down
2 changes: 1 addition & 1 deletion nmsr-aas/src/utils/png.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use image::{codecs::png::PngEncoder, ImageEncoder};
use tracing::trace_span;

use crate::error::{ExplainableExt, NMSRaaSError, Result};
use crate::error::{NMSRaaSError, Result};

pub(crate) fn create_png_from_bytes((width, height): (u32, u32), bytes: &[u8]) -> Result<Vec<u8>> {
let mut out = Vec::new();
Expand Down

0 comments on commit e621000

Please sign in to comment.