diff --git a/src/main.rs b/src/main.rs index 8c1c93c..f733e4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"); diff --git a/src/speak_proxy.rs b/src/speak_proxy.rs index 6b638a9..fbe199f 100644 --- a/src/speak_proxy.rs +++ b/src/speak_proxy.rs @@ -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, + remote_addr: SocketAddr, + router: Arc, + 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, remote_addr: SocketAddr,