refactor: s/LimitSpec/LimitSpecWithDuration/

I plan to make LimitSpec the type we use for the path config
with some options that do not require a duration, so rename
this particular type in preparation for that.

No functional change here.
This commit is contained in:
Wez Furlong
2025-01-06 06:53:08 -07:00
parent a3c7fe7d00
commit 359d15ca3f
2 changed files with 11 additions and 11 deletions
+4 -4
View File
@@ -35,7 +35,7 @@ use std::fmt::Debug;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, LazyLock};
use std::time::{Duration, Instant};
use throttle::limit::{LimitLease, LimitSpec};
use throttle::limit::{LimitLease, LimitSpecWithDuration};
use throttle::ThrottleSpec;
use tokio::sync::Notify;
use tokio::task::JoinHandle;
@@ -727,7 +727,7 @@ impl ReadyQueue {
let limit_name = format!("kumomta.connection_limit.{}", self.name);
let mut limits = vec![(
&limit_name,
LimitSpec {
LimitSpecWithDuration {
limit: path_config.connection_limit,
duration: lease_duration,
},
@@ -736,7 +736,7 @@ impl ReadyQueue {
for (label, limit) in &path_config.additional_connection_limits {
limits.push((
label,
LimitSpec {
LimitSpecWithDuration {
limit: *limit,
duration: lease_duration,
},
@@ -745,7 +745,7 @@ impl ReadyQueue {
// Check limits from smallest to largest so that we avoid
// taking up a slot from a larger one only to hit a smaller
// one and not do anything useful with the larger one
limits.sort_by_key(|(_, LimitSpec { limit, .. })| *limit);
limits.sort_by_key(|(_, LimitSpecWithDuration { limit, .. })| *limit);
'new_dispatcher: for _ in current_connection_count..ideal {
let mut leases = vec![];
+7 -7
View File
@@ -34,7 +34,7 @@ return redis.status_reply('OK')
)
});
pub struct LimitSpec {
pub struct LimitSpecWithDuration {
/// Maximum amount
pub limit: usize,
/// Maximum lease duration for a single count
@@ -56,7 +56,7 @@ enum Backend {
Redis,
}
impl LimitSpec {
impl LimitSpecWithDuration {
pub async fn acquire_lease<S: AsRef<str>>(&self, key: S) -> Result<LimitLease, Error> {
if let Some(redis) = REDIS.get() {
self.acquire_lease_redis(&redis, key.as_ref()).await
@@ -307,7 +307,7 @@ mod test {
#[tokio::test]
async fn test_memory() {
let limit = LimitSpec {
let limit = LimitSpecWithDuration {
limit: 2,
duration: Duration::from_secs(2),
};
@@ -342,7 +342,7 @@ mod test {
let redis = RedisServer::spawn("").await.unwrap();
let conn = redis.connection().await.unwrap();
let limit = LimitSpec {
let limit = LimitSpecWithDuration {
limit: 2,
duration: Duration::from_secs(2),
};
@@ -380,7 +380,7 @@ mod test {
let redis = RedisCluster::spawn().await.unwrap();
let conn = redis.connection().await.unwrap();
let limit = LimitSpec {
let limit = LimitSpecWithDuration {
limit: 2,
duration: Duration::from_secs(2),
};
@@ -412,7 +412,7 @@ mod test {
#[tokio::test]
async fn test_memory_extension() {
let limit = LimitSpec {
let limit = LimitSpecWithDuration {
limit: 1,
duration: Duration::from_secs(2),
};
@@ -447,7 +447,7 @@ mod test {
let redis = RedisServer::spawn("").await.unwrap();
let conn = redis.connection().await.unwrap();
let limit = LimitSpec {
let limit = LimitSpecWithDuration {
limit: 1,
duration: Duration::from_secs(2),
};