if I just read the docs, I would have figured this out sooner :|

This commit is contained in:
Brandon Thomas
2020-09-05 00:46:17 -04:00
parent 625dac6c19
commit 74de16f952
2 changed files with 20 additions and 2 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ pub mod speak_proxy;
use anyhow::Result as AnyhowResult;
use crate::newrelic_logger::{NewRelicLogger, MaybeNewRelicTransaction};
use crate::speak_proxy::speak_proxy;
use crate::speak_proxy::{speak_proxy, speak_proxy_with_retry};
use futures::future::{self, Future};
use hyper::Method;
use hyper::header::HeaderValue;
@@ -179,7 +179,7 @@ fn main() -> AnyhowResult<()> {
match (req.method(), req.uri().path()) {
(&Method::POST, "/speak") => {
let nr_transaction = newrelic_logger3.web_transaction("/speak");
speak_proxy(req, remote_addr.clone(), router3, nr_transaction, "/speak")
speak_proxy_with_retry(req, remote_addr.clone(), router3, nr_transaction, "/speak")
},
(&Method::POST, "/speak_spectrogram") => {
let nr_transaction = newrelic_logger3.web_transaction("/speak_spectrogram");
+18
View File
@@ -17,6 +17,7 @@ use std::fmt::Display;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
use futures::IntoFuture;
/// NB: This much match the shape of SpeakRequest in the 'voder/tts_service' code.
/// This is used for both /speak and /speak_spectrogram requests.
@@ -33,6 +34,23 @@ struct RequestDetails {
pub speaker: String,
}
pub fn speak_proxy_with_retry(
req: Request<Body>,
remote_addr: SocketAddr,
router: Arc<Router>,
transaction: MaybeNewRelicTransaction,
endpoint: &'static str) -> BoxFut
{
speak_proxy(req, remote_addr, router, transaction, endpoint)
.then(|result| {
match result {
Ok(t) => future::ok(t),
Err(t) => future::err(t),
}
})
.boxed()
}
pub fn speak_proxy(
req: Request<Body>,
remote_addr: SocketAddr,