added condition for rate limiting
This commit is contained in:
parent
790dac7c82
commit
b427311742
@ -6,6 +6,7 @@ use std::sync::Arc;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tokio::signal;
|
use tokio::signal;
|
||||||
|
use tower_governor::{governor::GovernorConfigBuilder, GovernorLayer};
|
||||||
use tower_http::trace::{self, TraceLayer};
|
use tower_http::trace::{self, TraceLayer};
|
||||||
use tracing_subscriber::{filter, layer::SubscriberExt, prelude::*, util::SubscriberInitExt};
|
use tracing_subscriber::{filter, layer::SubscriberExt, prelude::*, util::SubscriberInitExt};
|
||||||
|
|
||||||
@ -54,18 +55,25 @@ async fn main() {
|
|||||||
)
|
)
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
// tracing_subscriber::registry()
|
if std::env::var("RUST_ENV").expect("development") != "development" {
|
||||||
// .with(
|
println!("we're not in development, starting up the rate limiter");
|
||||||
// tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
|
let governor_conf = Arc::new(
|
||||||
// format!(
|
GovernorConfigBuilder::default()
|
||||||
// "{}=debug,tower_http=debug,axum=trace",
|
.per_second(2)
|
||||||
// env!("CARGO_CRATE_NAME")
|
.burst_size(5)
|
||||||
// )
|
.finish()
|
||||||
// .into()
|
.unwrap(),
|
||||||
// }),
|
);
|
||||||
// )
|
|
||||||
// .with(tracing_subscriber::fmt::layer())
|
let governor_limiter = governor_conf.limiter().clone();
|
||||||
// .init();
|
let interval = Duration::from_secs(60);
|
||||||
|
// a separate background task to clean up
|
||||||
|
std::thread::spawn(move || loop {
|
||||||
|
std::thread::sleep(interval);
|
||||||
|
tracing::info!("rate limiting storage size: {}", governor_limiter.len());
|
||||||
|
governor_limiter.retain_recent();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// grabbing the database url from our env variables
|
// grabbing the database url from our env variables
|
||||||
let db_connection_str = std::env::var("DATABASE_URL")
|
let db_connection_str = std::env::var("DATABASE_URL")
|
||||||
|
Loading…
Reference in New Issue
Block a user